#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int,int>
#define ret return
#define fr first
#define sc second
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define nosol puts("-1");
#define pb push_back
#define endi puts("");
const int N = 1e6+12,INF = 1e15+7;
#define ordered_set tree <int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int p[N],der[N],g[N],x[N];
void update(int v,int l,int r,int pos,int x){
if (l == r){
der[v] = x;
ret ;
}
int m = l+r>>1;
if (m < pos){
update((v<<1)+1,m+1,r,pos,x);
}
else update(v<<1,l,m,pos,x);
der[v] = max(der[v<<1],der[(v<<1)+1]);
}
int get_pos(int v,int l,int r,int x){
if (l == r)ret l;
int m = l+r>>1;
if (der[(v<<1)+1] >= x)ret get_pos((v<<1)+1,m+1,r,x);
ret get_pos(v<<1,l,m,x);
}
main(){
int n,i,a,b,ans=0;
cin>>n;
for (i=1;i<=n;++i){
cin>>x[i]>>a>>b;
g[i] = g[i-1]+a;
p[i] = p[i-1]+b;
update(1,1,n,i,p[i]-x[i]);
}
for (i=1;i<=n;++i){
int j = get_pos(1,1,n,p[i-1]-x[i]);
ans = max(ans,g[j]-g[i-1]);
}
cout <<ans;
}
Compilation message
divide.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int)':
divide.cpp:28:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | int m = l+r>>1;
| ~^~
divide.cpp: In function 'long long int get_pos(long long int, long long int, long long int, long long int)':
divide.cpp:38:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
38 | int m = l+r>>1;
| ~^~
divide.cpp: At global scope:
divide.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
44 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
6 ms |
460 KB |
Output is correct |
24 |
Correct |
5 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
6 ms |
460 KB |
Output is correct |
24 |
Correct |
5 ms |
460 KB |
Output is correct |
25 |
Correct |
6 ms |
460 KB |
Output is correct |
26 |
Correct |
7 ms |
776 KB |
Output is correct |
27 |
Correct |
9 ms |
716 KB |
Output is correct |
28 |
Correct |
46 ms |
2448 KB |
Output is correct |
29 |
Correct |
54 ms |
2508 KB |
Output is correct |
30 |
Correct |
121 ms |
4616 KB |
Output is correct |
31 |
Correct |
88 ms |
4640 KB |
Output is correct |
32 |
Correct |
86 ms |
4676 KB |
Output is correct |
33 |
Correct |
96 ms |
4600 KB |
Output is correct |
34 |
Correct |
94 ms |
4684 KB |
Output is correct |
35 |
Correct |
117 ms |
4704 KB |
Output is correct |
36 |
Correct |
103 ms |
4644 KB |
Output is correct |