#include <bits/stdc++.h>
using namespace std;
#define f(i, a, b) for (int i = a; i <= b; i++)
#define fo(i, a, b) for (int i = a; i >= b; i--)
#define minimize(a, b) a = (a < b ? a : b)
#define maximize(a, b) a = (a > b ? a : b)
#define int long long
#define fi first
#define se second
#define ll long long
#define pii pair <int, int>
#define pb push_back
#define pi acos(-1)
#define sz(a) (int)a.size()
#define getbit(a, b) (((a) >> (b)) & 1)
#define INOUT "main"
#define INFT 0x3f3f3f3f
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
cout << *it << " = [" << a << "]" << '\n';
err(++it, args...);
}
#define debug1(a, st, en) { cout << #a << " = ["; int kt = false; f(i, st, en) {if (kt) cout << ", "; kt = true; cout << a[i];} cout << "]\n"; }
void ctime()
{
cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
void file()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
if (fopen(INOUT".INP", "r"))
{
freopen(INOUT".INP", "r", stdin);
freopen(INOUT".OUT", "w", stdout);
}
}
const int MX_N = 1e5 + 5;
int n;
int x[MX_N], g[MX_N], e[MX_N], mx[MX_N];
signed main()
{
file();
cin >> n;
f(i, 1, n)
{
cin >> x[i] >> g[i] >> e[i];
g[i] += g[i - 1];
e[i] += e[i - 1];
}
f(i, 1, n + 1) mx[i] = -1e15;
fo(i, n, 1) mx[i] = max(mx[i + 1], e[i] - x[i]);
ll res = 0;
f(i, 1, n)
{
int l = i, r = n, ans;
while(l <= r)
{
int mid = (l + r) / 2;
if (mx[mid] >= e[i - 1] - x[i])
{
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
maximize(res, g[ans] - g[i - 1]);
}
cout << res;
ctime();
return 0;
}
Compilation message
divide.cpp: In function 'void file()':
divide.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | freopen(INOUT".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen(INOUT".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp: In function 'int main()':
divide.cpp:83:28: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
83 | maximize(res, g[ans] - g[i - 1]);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
472 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
464 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
472 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
464 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
484 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
528 KB |
Output is correct |
21 |
Correct |
0 ms |
356 KB |
Output is correct |
22 |
Correct |
0 ms |
540 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
472 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
464 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
484 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
528 KB |
Output is correct |
21 |
Correct |
0 ms |
356 KB |
Output is correct |
22 |
Correct |
0 ms |
540 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
612 KB |
Output is correct |
25 |
Correct |
1 ms |
616 KB |
Output is correct |
26 |
Correct |
1 ms |
872 KB |
Output is correct |
27 |
Correct |
2 ms |
872 KB |
Output is correct |
28 |
Correct |
8 ms |
3048 KB |
Output is correct |
29 |
Correct |
9 ms |
3180 KB |
Output is correct |
30 |
Correct |
18 ms |
6504 KB |
Output is correct |
31 |
Correct |
18 ms |
5272 KB |
Output is correct |
32 |
Correct |
15 ms |
5296 KB |
Output is correct |
33 |
Correct |
14 ms |
5212 KB |
Output is correct |
34 |
Correct |
14 ms |
5220 KB |
Output is correct |
35 |
Correct |
16 ms |
5456 KB |
Output is correct |
36 |
Correct |
17 ms |
5716 KB |
Output is correct |