Submission #534908

#TimeUsernameProblemLanguageResultExecution timeMemory
534908amunduzbaevArt Exhibition (JOI18_art)C++17
100 / 100
210 ms24756 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]); //~ }); sort(a + 1, a + n + 1); 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++){ mx = max(mx, a[i][0] - pref[i-1]); res = max(res, pref[i] - a[i][0] + mx); } 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...