# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
789709 | Bula | Art Exhibition (JOI18_art) | C++17 | 1 ms | 212 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;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int ll
const ll mod=1e9+7;
main(){
int n;
cin>>n;
vector< pair<int,int> > v(n+1);
int sum = 0;
for(int i=1;i<=n;i++){
cin>>v[i].first>>v[i].second;
sum += v[i].second;
}
sort(all(v));
int l = 1,r = n,mx = v[n].first,mn = v[1].first,ans = sum - (mx - mn),c = sum;
//cout << ans << endl;
for(int i=n;i>=1;i--){
int cur = c - (v[i].first - mn);
if(cur >= ans){
ans = cur;
r = i;
}
c -= v[i].second;
}
//cout << ans << endl;
for(int i=1;i<=r;i++){
int cur = c - (v[r].first - v[i].first);
if(cur >= ans){
ans = cur;
l = i;
}
c -= v[i].second;
}
cout << ans << endl;
}
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... |