# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1110747 | luvna | Art Exhibition (JOI18_art) | C++14 | 145 ms | 24764 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 all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
typedef long long ll;
const int N = 5e5 + 15;
int n;
pair<ll,ll> a[N];
ll pref[N];
ll ans = 0;
void solve(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i].first >> a[i].second;
}
sort(a + 1, a + 1 + n);
for(int i = 1; i <= n; i++) pref[i] = pref[i-1] + a[i].second;
ll maxx = -INT_MAX;
for(int i = 1; i <= n; i++){
maxx = max(maxx, a[i].first - pref[i-1]);
ans = max(ans, pref[i] - a[i].first + maxx);
}
cout << ans;
}
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
#define task "task"
if(fopen(task".INP", "r")){
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
int t; t = 1; //cin >> t;
while(t--) solve();
}
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... |