Submission #377956

#TimeUsernameProblemLanguageResultExecution timeMemory
377956cpp219Art Exhibition (JOI18_art)C++14
100 / 100
695 ms32108 KiB
#pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include<bits/stdc++.h> #define ll long long #define ld long double #define fs first #define sc second using namespace std; typedef pair<ll,ll> LL; const ll N = 5e5 + 9; const ll inf = 1e9 + 7; ll n,st[4*N],lazy[4*N]; LL a[N]; void Pass(ll id){ ll t = lazy[id]; lazy[id] = 0; st[id*2] += t; lazy[id*2] += t; st[id*2 + 1] += t; lazy[id*2 + 1] += t; } void upd(ll id,ll l,ll r,ll u,ll v,ll val){ if (v < l||r < u) return; if (u <= l&&r <= v){ st[id] += val; lazy[id] += val; return; } ll mid = (l + r)/2; Pass(id); upd(id*2,l,mid,u,v,val); upd(id*2 + 1,mid + 1,r,u,v,val); st[id] = max(st[id*2],st[id*2 + 1]); } ll Get(ll id,ll l,ll r,ll u,ll v){ if (v < l||r < u) return 0; if (u <= l&&r <= v) return st[id]; ll mid = (l + r)/2; Pass(id); return max(Get(id*2,l,mid,u,v),Get(id*2 + 1,mid + 1,r,u,v)); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "tst" if (fopen(task".INP","r")){ freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } cin>>n; for (ll i = 1;i <= n;i++) cin>>a[i].fs>>a[i].sc; sort(a + 1,a + n + 1); ll cur = 0,ans = 0; for (ll i = 1;i <= n;i++){ cur += a[i].sc; upd(1,1,n,i,i,cur - a[i].fs + a[1].fs); } ans = max(ans,Get(1,1,n,1,n)); //cout<<ans; return 0; for (ll i = 2;i <= n;i++){ upd(1,1,n,i,n,a[i].fs - a[i - 1].fs - a[i - 1].sc); ans = max(ans,Get(1,1,n,i,n)); //cout<<Get(1,1,n,i,n)<<"x\n"; } cout<<ans; }

Compilation message (stderr)

art.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
art.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
art.cpp: In function 'int main()':
art.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   46 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...