#include <bits/stdc++.h>
using namespace std;
main()
{
long long n;
cin >> n;
vector<long long> x(n+1), g(n+1), d(n+1), g1(n+1, 0), d1(n+1, 0);
for (long long i = 1; i <= n; ++i)
{
cin >> x[i] >> g[i] >> d[i];
g1[i] = g1[i-1] + g[i];
d1[i] = d1[i-1] + d[i];
}
vector <long long> h(n+2);
for (long long i=1; i<=n+1; i++) h[i]=-1e15;
for (long long i=n; i>=1; i--) h[i]=max(h[i+1],d1[i]-x[i]);
long long res = 0;
for (long long i=1; i<=n; i++)
{
long long l = i, r = n, temp;
while(l <= r)
{
long long mid = (l + r) / 2;
if (h[mid] >= d1[i - 1] - x[i])
{
temp = mid;
l = mid + 1;
}
else r = mid - 1;
}
res=max(res,g1[temp] - g1[i - 1]);
}
cout << res;
return 0;
}
Compilation message
divide.cpp:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
4 | main()
| ^~~~
divide.cpp: In function 'int main()':
divide.cpp:36:28: warning: 'temp' may be used uninitialized in this function [-Wmaybe-uninitialized]
36 | res=max(res,g1[temp] - g1[i - 1]);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
604 KB |
Output is correct |
24 |
Correct |
3 ms |
612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
604 KB |
Output is correct |
24 |
Correct |
3 ms |
612 KB |
Output is correct |
25 |
Correct |
2 ms |
612 KB |
Output is correct |
26 |
Correct |
3 ms |
868 KB |
Output is correct |
27 |
Correct |
5 ms |
1012 KB |
Output is correct |
28 |
Correct |
24 ms |
3804 KB |
Output is correct |
29 |
Correct |
31 ms |
3932 KB |
Output is correct |
30 |
Correct |
62 ms |
7932 KB |
Output is correct |
31 |
Correct |
44 ms |
6748 KB |
Output is correct |
32 |
Correct |
54 ms |
6920 KB |
Output is correct |
33 |
Correct |
43 ms |
6748 KB |
Output is correct |
34 |
Correct |
42 ms |
6576 KB |
Output is correct |
35 |
Correct |
53 ms |
7108 KB |
Output is correct |
36 |
Correct |
63 ms |
7260 KB |
Output is correct |