# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
299786 | NicolaAbusaad2014 | Art Exhibition (JOI18_art) | C++14 | 215 ms | 24856 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |