#include<bits/stdc++.h>
using namespace std;
const int MAXN=100005,INF=1e9;
long long prefg[MAXN],prefd[MAXN];
int x[MAXN],bit[2*MAXN],MAX;
map<long long,int> mp;
int query(int now){
int ret=INF;
for(int i=now;i>0;i-=(i&(-i)))ret=min(ret,bit[i]);
return ret;
}
void update(int now,int val){
for(int i=now;i<=MAX;i+=(i&(-i)))bit[i]=min(bit[i],val);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
for(int i=0;i<2*MAXN;i++)bit[i]=INF;
int n,g,d;
cin >> n;
for(int i=1;i<=n;i++){
cin >> x[i];
cin >> g >> d;
prefg[i]=prefg[i-1]+g;
prefd[i]=prefd[i-1]+d;
}
for(int i=0;i<=n;i++){
mp[prefd[i]-x[i+1]];
if(i)mp[prefd[i]-x[i]];
}
for(map<long long,int>::iterator it=mp.begin();it!=mp.end();++it){
MAX++;
mp[it->first]=MAX;
}
long long ans=0;
update(mp[prefd[0]-x[1]],1);
for(int i=1;i<=n;i++){
int idx=query(mp[prefd[i]-x[i]]);
if(idx!=INF){
ans=max(ans,prefg[i]-prefg[idx-1]);
}
update(mp[prefd[i]-x[i+1]],i+1);
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1132 KB |
Output is correct |
2 |
Correct |
1 ms |
1132 KB |
Output is correct |
3 |
Correct |
1 ms |
1132 KB |
Output is correct |
4 |
Correct |
1 ms |
1132 KB |
Output is correct |
5 |
Correct |
1 ms |
1132 KB |
Output is correct |
6 |
Correct |
1 ms |
1132 KB |
Output is correct |
7 |
Correct |
1 ms |
1132 KB |
Output is correct |
8 |
Correct |
1 ms |
1132 KB |
Output is correct |
9 |
Correct |
1 ms |
1132 KB |
Output is correct |
10 |
Correct |
1 ms |
1132 KB |
Output is correct |
11 |
Correct |
1 ms |
1132 KB |
Output is correct |
12 |
Correct |
1 ms |
1132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1132 KB |
Output is correct |
2 |
Correct |
1 ms |
1132 KB |
Output is correct |
3 |
Correct |
1 ms |
1132 KB |
Output is correct |
4 |
Correct |
1 ms |
1132 KB |
Output is correct |
5 |
Correct |
1 ms |
1132 KB |
Output is correct |
6 |
Correct |
1 ms |
1132 KB |
Output is correct |
7 |
Correct |
1 ms |
1132 KB |
Output is correct |
8 |
Correct |
1 ms |
1132 KB |
Output is correct |
9 |
Correct |
1 ms |
1132 KB |
Output is correct |
10 |
Correct |
1 ms |
1132 KB |
Output is correct |
11 |
Correct |
1 ms |
1132 KB |
Output is correct |
12 |
Correct |
1 ms |
1132 KB |
Output is correct |
13 |
Correct |
1 ms |
1132 KB |
Output is correct |
14 |
Correct |
1 ms |
1132 KB |
Output is correct |
15 |
Correct |
2 ms |
1260 KB |
Output is correct |
16 |
Correct |
2 ms |
1260 KB |
Output is correct |
17 |
Correct |
2 ms |
1260 KB |
Output is correct |
18 |
Correct |
3 ms |
1408 KB |
Output is correct |
19 |
Correct |
2 ms |
1260 KB |
Output is correct |
20 |
Correct |
2 ms |
1280 KB |
Output is correct |
21 |
Correct |
3 ms |
1388 KB |
Output is correct |
22 |
Correct |
3 ms |
1388 KB |
Output is correct |
23 |
Correct |
20 ms |
1900 KB |
Output is correct |
24 |
Correct |
6 ms |
2028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1132 KB |
Output is correct |
2 |
Correct |
1 ms |
1132 KB |
Output is correct |
3 |
Correct |
1 ms |
1132 KB |
Output is correct |
4 |
Correct |
1 ms |
1132 KB |
Output is correct |
5 |
Correct |
1 ms |
1132 KB |
Output is correct |
6 |
Correct |
1 ms |
1132 KB |
Output is correct |
7 |
Correct |
1 ms |
1132 KB |
Output is correct |
8 |
Correct |
1 ms |
1132 KB |
Output is correct |
9 |
Correct |
1 ms |
1132 KB |
Output is correct |
10 |
Correct |
1 ms |
1132 KB |
Output is correct |
11 |
Correct |
1 ms |
1132 KB |
Output is correct |
12 |
Correct |
1 ms |
1132 KB |
Output is correct |
13 |
Correct |
1 ms |
1132 KB |
Output is correct |
14 |
Correct |
1 ms |
1132 KB |
Output is correct |
15 |
Correct |
2 ms |
1260 KB |
Output is correct |
16 |
Correct |
2 ms |
1260 KB |
Output is correct |
17 |
Correct |
2 ms |
1260 KB |
Output is correct |
18 |
Correct |
3 ms |
1408 KB |
Output is correct |
19 |
Correct |
2 ms |
1260 KB |
Output is correct |
20 |
Correct |
2 ms |
1280 KB |
Output is correct |
21 |
Correct |
3 ms |
1388 KB |
Output is correct |
22 |
Correct |
3 ms |
1388 KB |
Output is correct |
23 |
Correct |
20 ms |
1900 KB |
Output is correct |
24 |
Correct |
6 ms |
2028 KB |
Output is correct |
25 |
Correct |
7 ms |
1900 KB |
Output is correct |
26 |
Correct |
10 ms |
2668 KB |
Output is correct |
27 |
Correct |
10 ms |
2796 KB |
Output is correct |
28 |
Correct |
53 ms |
9432 KB |
Output is correct |
29 |
Correct |
57 ms |
9708 KB |
Output is correct |
30 |
Correct |
137 ms |
18560 KB |
Output is correct |
31 |
Correct |
136 ms |
17408 KB |
Output is correct |
32 |
Correct |
129 ms |
17364 KB |
Output is correct |
33 |
Correct |
99 ms |
17260 KB |
Output is correct |
34 |
Correct |
103 ms |
16748 KB |
Output is correct |
35 |
Correct |
126 ms |
17772 KB |
Output is correct |
36 |
Correct |
97 ms |
17900 KB |
Output is correct |