Submission #299786

#TimeUsernameProblemLanguageResultExecution timeMemory
299786NicolaAbusaad2014Art Exhibition (JOI18_art)C++14
100 / 100
215 ms24856 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n,x,z,ans=0,a,b,mx=0; cin>>n; a=0; b=n-1; pair<long long,long long>arr[n]; for(long i=0;i<n;i++){ cin>>arr[i].first>>arr[i].second; ans+=arr[i].second; mx=max(mx,arr[i].second); } sort(arr,arr+n); ans-=(arr[n-1].first-arr[0].first); x=0; z=ans; long long add[n]; add[0]=0; for(long i=1;i<n;i++){ x-=arr[i-1].second; x+=arr[i].first-arr[i-1].first; add[i]=max(add[i-1],x); } a=0; x=0; for(long i=n-2;i>=0;i--){ x-=arr[i+1].second; x+=arr[i+1].first-arr[i].first; a=max(a,x); ans=max(ans,z+add[i]+a); } ans=max(ans,mx); cout<<ans<<endl; return 0; }

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:9:29: warning: variable 'b' set but not used [-Wunused-but-set-variable]
    9 |     long long n,x,z,ans=0,a,b,mx=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...