Submission #534890

#TimeUsernameProblemLanguageResultExecution timeMemory
534890amunduzbaevArt Exhibition (JOI18_art)C++17
0 / 100
1 ms332 KiB
#include "bits/stdc++.h" using namespace std; #define ar array #define int long long const int N = 5e5 + 5; ar<int, 2> a[N]; int pref[N]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i][0]>>a[i][1]; } sort(a+1, a+n+1, [&](ar<int, 2>& a, ar<int, 2>& b){ return (a[0] < b[0]); }); //~ for(int i=1;i<=n;i++) cout<<a[i][0]<<" "<<a[i][1]<<"\n"; for(int i=1;i<=n;i++) pref[i] = pref[i-1] + a[i][1]; int mx = -1e18, res = -1e18; for(int i=1;i<=n;i++){ res = max(res, pref[i] - a[i][0] + mx); mx = max(mx, a[i][0] - pref[i-1]); } cout<<res<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...