Submission #786766

#TimeUsernameProblemLanguageResultExecution timeMemory
786766winter0101Art Exhibition (JOI18_art)C++14
100 / 100
174 ms32548 KiB
#include <bits/stdc++.h> using namespace std; struct lena{ long long a,b; }a[500001]; long long pf[500001]; long long rl[500001]; long long sf[500001]; bool cmp(const lena &p, const lena &q){ return p.a<q.a; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen(".INP","r",stdin); // freopen(".OUT","w",stdout); int n; cin>>n; for (int i=1;i<=n;i++){ cin>>a[i].a>>a[i].b; } sort(a+1,a+1+n,cmp); for (int i=1;i<=n;i++){ pf[i]=pf[i-1]+a[i].b; } for (int i=1;i<=n;i++){ rl[i]=pf[i]-a[i].a; } sf[n]=rl[n]; for (int i=n-1;i>=1;i--){ sf[i]=max(sf[i+1],rl[i]); } long long ans=-1e16; for (int i=1;i<=n;i++){ ans=max(ans,sf[i]+a[i].a-pf[i-1]); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...