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 <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <climits>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define pii pair <int,int>
#define r0 return 0
using namespace std;
const int N = 5 * 1e5 + 5;
int x,m,k,n,l,r,ans,cheese;
int pref[N],p[N],mn;
pii a[N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].ff >> a[i].ss;
}
sort(a + 1,a + 1 + n);
p[0] = -a[1].ff;
pref[0] = 0;
for (int i = 1; i <= n; i++){
pref[i] = pref[i - 1] + a[i].ss;
p[i] = min(p[i - 1],pref[i] - a[i + 1].ff);
}
k = -LLONG_MAX;
for (int i = 1; i <= n; i++) {
k = max(k,pref[i] - a[i].ff - p[i - 1]);
}
cout << k << endl;
r0;
}
# | 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... |