Submission #529671

#TimeUsernameProblemLanguageResultExecution timeMemory
529671KenjikrabDivide and conquer (IZhO14_divide)C++14
100 / 100
104 ms7112 KiB
#include<bits/stdc++.h> #define int long long #define db double #define pb push_back #define pii pair<int,int> #define fi first #define se second #define loop(i,j,k) for(int i=j;i<k;i++) using namespace std; signed main(){ //ios_base::sync_with_stdio(false);cin.tie(0); int n; cin>>n; int ans=0; vector<int> x,g,p; x.pb(0); g.pb(0); p.pb(0); for(int i=0;i<n;i++){ int a,b,c; cin>>a>>b>>c; x.pb(a); g.pb(g[i]+b); p.pb(p[i]+c); } vector<pii> diff; ans=g[n]-g[n-1]; diff.pb({x[n]-p[n],g[n]}); for(int i=n-1;i>0;i--){ if(x[i]-p[i]<diff.back().fi) diff.pb({x[i]-p[i],g[i]}); int con=x[i]-p[i-1]; int l=0,r=diff.size()-1; while(l<r){ int mid=(l+r)/2; if(diff[mid].fi>con) l=mid+1; else r=mid; } if(diff[l].fi<=con) ans=max(ans,diff[l].se-g[i-1]); else ans=max(ans,g[i]-g[i-1]); } cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...