Submission #372347

#TimeUsernameProblemLanguageResultExecution timeMemory
372347mariowongArt Exhibition (JOI18_art)C++14
100 / 100
246 ms32748 KiB
#include <bits/stdc++.h> using namespace std; long long n,l; long long ans,b[500005],mx[500005],ps[500005]; pair<long long,long long> a[500005]; int main(){ ios::sync_with_stdio(false); cin >> n; for (int i=1;i<=n;i++){ cin >> a[i].first >> a[i].second; } sort(a+1,a+1+n); for (int i=1;i<=n;i++){ ps[i]=ps[i-1]+a[i].second; b[i]=ps[i]-a[i].first; } mx[n+1]=-1e18; for (int i=n;i>=1;i--){ mx[i]=max(mx[i+1],b[i]); } ans=-1e18; for (int i=1;i<=n;i++){ ans=max(ans,mx[i]+a[i].first-ps[i-1]); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...