# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
924821 | SalihSahin | Art Exhibition (JOI18_art) | C++17 | 173 ms | 36748 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>
#define pb push_back
#define int long long
#define mp make_pair
using namespace std;
const int mod = 998244353;
const int inf = 1e16;
const int N = 55;
int32_t main(){
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio(false);
int n;
cin>>n;
vector<pair<int, int> > a(n);
vector<int> vp(n+1);
for(int i = 0; i < n; i++){
cin>>a[i].first>>a[i].second;
}
sort(a.begin(), a.end());
for(int i = 0; i < n; i++){
vp[i+1] = vp[i] + a[i].second;
}
vector<pair<int, int> > pre(n);
vector<int> v(n);
v[0] = a[0].second;
for(int i = 1; i < n; i++){
v[i] = a[i].second - (a[i].first - a[i-1].first);
}
pre[0].first = v[0];
pre[0].second = 0;
for(int i = 1; i < n; i++){
pre[i].first = pre[i-1].first + v[i];
pre[i].second = i;
}
sort(pre.rbegin(), pre.rend());
int pind = 0;
int ans = 0;
for(int i = 0; i < n; i++){
while(pind < pre.size()-1 && pre[pind].second < i){
pind++;
}
int x = pre[pind].second;
int c = (vp[x+1] - vp[i]) - (a[x].first - a[i].first);
ans = max(ans, c);
}
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... |