#include<bits/stdc++.h>
#define int long long
#define db double
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define loop(i,j,k) for(int i=j;i<k;i++)
using namespace std;
signed main(){
//ios_base::sync_with_stdio(false);cin.tie(0);
int n;
cin>>n;
int ans=0;
vector<int> x,g,p;
x.pb(0);
g.pb(0);
p.pb(0);
for(int i=0;i<n;i++){
int a,b,c;
cin>>a>>b>>c;
x.pb(a);
g.pb(g[i]+b);
p.pb(p[i]+c);
}
vector<pii> diff;
ans=g[n]-g[n-1];
diff.pb({x[n]-p[n],g[n]});
for(int i=n-1;i>0;i--){
if(x[i]-p[i]<diff.back().fi) diff.pb({x[i]-p[i],g[i]});
int con=x[i]-p[i-1];
int l=0,r=diff.size()-1;
while(l<r){
int mid=(l+r)/2;
if(diff[mid].fi>con) l=mid+1;
else r=mid;
}
if(diff[l].fi<=con) ans=max(ans,diff[l].se-g[i-1]);
else ans=max(ans,g[i]-g[i-1]);
}
cout<<ans;
return 0;
}
# |
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 |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 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 |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 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 |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 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 |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 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 |
292 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
308 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
5 ms |
704 KB |
Output is correct |
24 |
Correct |
5 ms |
680 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 |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 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 |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 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 |
292 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
308 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
5 ms |
704 KB |
Output is correct |
24 |
Correct |
5 ms |
680 KB |
Output is correct |
25 |
Correct |
3 ms |
460 KB |
Output is correct |
26 |
Correct |
6 ms |
716 KB |
Output is correct |
27 |
Correct |
10 ms |
896 KB |
Output is correct |
28 |
Correct |
47 ms |
2728 KB |
Output is correct |
29 |
Correct |
51 ms |
2832 KB |
Output is correct |
30 |
Correct |
104 ms |
5620 KB |
Output is correct |
31 |
Correct |
75 ms |
4444 KB |
Output is correct |
32 |
Correct |
77 ms |
4664 KB |
Output is correct |
33 |
Correct |
71 ms |
4340 KB |
Output is correct |
34 |
Correct |
73 ms |
5764 KB |
Output is correct |
35 |
Correct |
88 ms |
6968 KB |
Output is correct |
36 |
Correct |
94 ms |
7112 KB |
Output is correct |