Submission #772649

#TimeUsernameProblemLanguageResultExecution timeMemory
772649NintsiChkhaidzeArt Exhibition (JOI18_art)C++17
100 / 100
623 ms41148 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define s second #define f first #define pll pair <ll,ll> #define pii pair <int,int> #define left h*2,l,(l + r)/2 #define right h*2+1,(l + r)/2 + 1,r using namespace std; const int N = 5e5 + 5; ll t[4*N],lz[4*N],p[N]; pll d[N]; void push(int h){ if (lz[h] == 0) return; lz[h*2] += lz[h]; lz[h*2 + 1] += lz[h]; t[h*2] += lz[h]; t[h*2 + 1] += lz[h]; lz[h] = 0; } void upd(int h,int l,int r,int L,int R,ll val){ if (r < L || R < l) return ; if (L <= l && r <= R){ t[h] += val; lz[h] += val; return; } push(h); upd(left,L,R,val); upd(right,L,R,val); t[h] = max(t[h*2],t[h*2+1]); } ll get(int h,int l,int r,int L,int R){ if (r < L || R < l) return 0; if (L <= l && r <= R) return t[h]; push(h); return max(get(left,L,R),get(right,L,R)); } signed main() { ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n; cin>>n; for (int i = 1; i <= n; i++){ cin>>d[i].f>>d[i].s; } sort(d + 1,d + n + 1); d[0].f = d[1].f; for (int i = 1; i <= n; i++){ p[i] = p[i - 1] + d[i].s - (d[i].f - d[i - 1].f); upd(1,1,n,i,i,p[i]); } ll ans = 0; for (int i = 1; i <= n; i++){ ans = max(ans, get(1,1,n,i,n)); ll val = get(1,1,n,i,i); upd(1,1,n,i + 1,n,-val + (d[i + 1].f - d[i].f)); } 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...