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;
long long n,x[100005],g[100005],d[100005],cv[100005],f[100005],ans=0;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen(".inp","r",stdin);
// freopen(".out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x[i]>>g[i]>>d[i];
cv[i]=cv[i-1]+g[i];
f[i]=f[i-1]+d[i];
}
vector<long long> v,u;
v.push_back(f[0]-x[1]);
u.push_back(1);
ans=g[1];
for(int i=2;i<=n;i++)
{
long long vl=f[i-1]-x[i];
if(vl<v[v.size()-1]) {v.push_back(vl);u.push_back(i);}
long long k=f[i]-x[i];
long long l=0,r=v.size()-1,vt=-1;
while(l<=r)
{
long long mid=(l+r)/2;
if(v[mid]<=k)
{
r=mid-1;
vt=mid;
}
else l=mid+1;
}
// cout<<k<<' '<<vt<<endl;
if(vt==-1) continue;
long long h=u[vt];
// cout<<k<<' '<<h<<' '<<i<<endl;
ans=max(ans,cv[i]-cv[h-1]);
}
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |