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>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL long long
#define st first
#define nd second
#define endl '\n'
using namespace std;
const int MAXN=100005;
LL f[MAXN*4],lz[MAXN*4],n,x[MAXN],g[MAXN],d[MAXN],p[MAXN],ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;++i) {
cin>>x[i]>>g[i]>>d[i];
d[i]+=d[i-1];
g[i]+=g[i-1];
}
for(int i=n;i>=1;--i) {
if(i==n) p[i]=d[i]-x[i];
else p[i]=max(p[i+1],d[i]-x[i]);
}
for(int i=1;i<=n;++i) {
int l=i,r=n+1,md;
while(l+1<r) {
md=(l+r)/2;
if(p[md]>=d[i-1]-x[i])
l=md;
else r=md;
}
ans=max(ans,g[l]-g[i-1]);
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |