Submission #171710

#TimeUsernameProblemLanguageResultExecution timeMemory
171710dennisstarArt Exhibition (JOI18_art)C++11
100 / 100
334 ms36924 KiB
#include <bits/stdc++.h> #define fi first #define se second #define ryan bear #define all(V) ((V).begin()), ((V).end()) using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef long double ld; typedef vector<int> vim; typedef vector<ll> vlm; int N; pll ar[500010]; ll B[500010], C[500010]; ll seg[(1<<20)]; ll x, y; ll mx(int fr, int re) { fr+=(1<<19); re+=(1<<19); ll ret=seg[0]; while (fr<=re) { if (fr%2) ret=max(ret, seg[fr++]); if (re%2==0) ret=max(ret, seg[re--]); fr/=2; re/=2; } return ret; } int main() { scanf("%d", &N); for (int i=0; i<N; i++) { scanf("%lld %lld", &x, &y); ar[i]={x, y}; } sort(ar, ar+N); for (int i=0; i<N; i++) B[i]=ar[i].se, C[i]=ar[i].fi+ar[i].se-ar[i+1].fi; for (int i=N-1; i>=0; i--) seg[i+(1<<19)]=seg[i+1+(1<<19)]+C[i]; for (int i=(1<<19)-1; i; i--) seg[i]=max(seg[i*2], seg[i*2+1]); ll ans=B[0], s=0; for (int i=N-1; i; i--) { s+=C[i]; ans=max(ans, mx(0, i-1)-s+B[i]); ans=max(ans, B[i]); } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
art.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...