#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll x[100005];
ll g[100005];
ll d[100005];
ll pos[100005];
pair<ll,ll>vec[100005];
int n;
int main(){
cin >> n;
for(int i=1;i<=n;i++){
cin>>x[i]>>g[i]>>d[i];
g[i]=g[i]+g[i-1];
d[i]+=d[i-1];
vec[i]=(make_pair(d[i]-x[i],i));
}
sort(vec+1,vec+n+1);
for(int i=n;i>0;i--){
pos[i]=max(pos[i+1],vec[i].second);
}
ll res=0;
for(int i=1;i<=n;i++){
int mn=d[i-1]-x[i];
int l=0,r=n;
if(r-l>0){
int mid=(l+r+1)/2;
if(vec[mid].first>=mn) r = mid;
else l=mid;
}
res=max(res,g[pos[r]]-g[i-1]);
}
cout << res << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
632 KB |
Output is correct |
2 |
Correct |
15 ms |
888 KB |
Output is correct |
3 |
Correct |
18 ms |
1016 KB |
Output is correct |
4 |
Correct |
86 ms |
2808 KB |
Output is correct |
5 |
Correct |
108 ms |
2832 KB |
Output is correct |
6 |
Correct |
225 ms |
5252 KB |
Output is correct |
7 |
Correct |
155 ms |
5160 KB |
Output is correct |
8 |
Correct |
171 ms |
5112 KB |
Output is correct |
9 |
Correct |
150 ms |
5228 KB |
Output is correct |
10 |
Incorrect |
150 ms |
5368 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |