#include <bits/stdc++.h>
#define N 200005
using namespace std;
long long preg[N];
long long pree[N];
int x[N];
struct SegTree{
vector<long long> t;
int n;
SegTree(int size){
n = size;
t.assign(4*n,1e18);
}
void upd(int v,int tl,int tr,int pos,long long val){
if(tl == tr){
t[v] = min(t[v],val);
return;
}
int tm = (tl + tr)/2;
if(pos <= tm)
upd(v*2,tl,tm,pos,val);
else upd(v*2+1,tm+1,tr,pos,val);
t[v] = min(t[v*2],t[v*2+1]);
}
long long get(int v,int tl,int tr,int l,int r){
if(tr < l || r < tl)
return 1e18;
if(l <= tl && tr <= r)
return t[v];
int tm = (tl + tr)/2;
return min(get(v*2,tl,tm,l,r),get(v*2+1,tm+1,tr,l,r));
}
void upd(int pos,long long val){
upd(1,1,n,pos,val);
}
long long get(int l,int r){
return get(1,1,n,l,r);
}
};
void solve(){
int n;
cin >> n;
vector<long long> compress;
for(int i = 1;i<=n;i++){
cin >> x[i];
int g,e;
cin >> g >> e;
preg[i] = preg[i-1] + g;
pree[i] = pree[i-1] + e;
compress.push_back(x[i] - pree[i]);
compress.push_back(x[i] - pree[i-1]);
}
sort(compress.begin(),compress.end());
compress.resize(unique(compress.begin(),compress.end())-compress.begin());
SegTree t(compress.size());
long long ans = 0;
for(int i = 1;i<=n;i++){
t.upd(lower_bound(compress.begin(),compress.end(),x[i]-pree[i-1]) - compress.begin()+1 ,preg[i-1]);
ans = max(ans,preg[i] - t.get(lower_bound(compress.begin(),compress.end(),x[i]-pree[i]) - compress.begin()+1 ,compress.size()));
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while(t--){
solve();
}
#ifdef Local
cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds.";
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
6 ms |
980 KB |
Output is correct |
24 |
Correct |
5 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
6 ms |
980 KB |
Output is correct |
24 |
Correct |
5 ms |
980 KB |
Output is correct |
25 |
Correct |
4 ms |
980 KB |
Output is correct |
26 |
Correct |
6 ms |
1368 KB |
Output is correct |
27 |
Correct |
7 ms |
1368 KB |
Output is correct |
28 |
Correct |
33 ms |
5384 KB |
Output is correct |
29 |
Correct |
33 ms |
5376 KB |
Output is correct |
30 |
Correct |
71 ms |
10256 KB |
Output is correct |
31 |
Correct |
61 ms |
10188 KB |
Output is correct |
32 |
Correct |
75 ms |
10256 KB |
Output is correct |
33 |
Correct |
65 ms |
10192 KB |
Output is correct |
34 |
Correct |
62 ms |
9972 KB |
Output is correct |
35 |
Correct |
62 ms |
10228 KB |
Output is correct |
36 |
Correct |
66 ms |
10252 KB |
Output is correct |