This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn=1e5+5;
int n,x,g,e;
ll p[maxn],T[4*maxn],jog[maxn],ans;
void upd(int pos,ll val,int l,int r,int nd){
if(l == r){
T[nd]=val;
return;
}
if(pos <= (l+r)/2) upd(pos,val,l,(l+r)/2,nd*2);
else upd(pos,val,(l+r)/2+1,r,nd*2+1);
T[nd] = max(T[nd*2],T[nd*2+1]);
}
int tap(ll val,int l,int r,int nd){
if(l==r) return l;
if(T[nd*2] >= val) return tap(val,l,(l+r)/2,nd*2);
return tap(val,(l+r)/2+1,r,nd*2+1);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 1;i <= n;i++){
cin >> x >> g >> e;
p[i]=p[i-1]+e;
jog[i]=jog[i-1]+g;
upd(i,x - p[i-1],1,n,1);
int pos=tap(x-p[i],1,n,1);
ans = max(ans,jog[i]-jog[pos-1]);
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |