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 ar array
#define int long long
const int N = 5e5 + 5;
ar<int, 2> a[N];
int pref[N];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i][0]>>a[i][1];
}
sort(a+1, a+n+1, [&](ar<int, 2>& a, ar<int, 2>& b){
return (a[0] < b[0]);
});
//~ for(int i=1;i<=n;i++) cout<<a[i][0]<<" "<<a[i][1]<<"\n";
for(int i=1;i<=n;i++) pref[i] = pref[i-1] + a[i][1];
int mx = -1e18, res = -1e18;
for(int i=1;i<=n;i++){
res = max(res, pref[i] - a[i][0] + mx);
mx = max(mx, a[i][0] - pref[i-1]);
}
cout<<res<<"\n";
}
# | 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... |