제출 #506144

#제출 시각아이디문제언어결과실행 시간메모리
506144lucriArt Exhibition (JOI18_art)C++17
100 / 100
649 ms16068 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); 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...