Submission #506137

#TimeUsernameProblemLanguageResultExecution timeMemory
506137lucriArt Exhibition (JOI18_art)C++17
0 / 100
1 ms204 KiB
#include <iostream> #include <algorithm> using namespace std; long long s,n,r,ss[500010],sd[500010],r2; struct tablouri{long long a,b;}t[500010]; bool comp(tablouri a1,tablouri b1) { return a1.a<b1.a; } int main() { cin>>n; for(long long i=1;i<=n;++i) { cin>>t[i].a>>t[i].b; s+=t[i].b; } sort(t+1,t+n+1,comp); long long j=1,i; for(long long i=1;i<=n;++i) { if(t[i].a==t[j].a) t[j].b+=t[i].b; else { ++j; t[j]=t[i]; } } n=j; r=s-t[n].a+t[1].a; long long sp=0; for(long long i=2;i<=n;++i) { sp+=t[i-1].b; ss[i]=t[i].a-sp-t[1].a; ss[i]=max(ss[i-1],ss[i]); } sp=0; for(long long i=n-1;i>=1;--i) { sp+=t[i+1].b; sd[i]=t[n].a-sp-t[i].a; sd[i]=max(sd[i],sd[i+1]); } for(long long i=1;i<=n;++i) r2=max(r2,sd[i]+ss[i]); cout<<r+r2; return 0; }

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:19:19: warning: unused variable 'i' [-Wunused-variable]
   19 |     long long j=1,i;
      |                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...