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 <algorithm>
#define f first
#define s second
using namespace std;
long long n, ans, ps[500010], maxx[500010];
pair<long long, long long> a[500010];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].f >> a[i].s;
sort(a+1,a+n+1);
for (int i = 1; i <= n; i++) ps[i] = ps[i-1]+a[i].s;
for (int i = n; i >= 1; i--) maxx[i] = max(maxx[i+1],ps[i]-a[i].f);
for (int i = 1; i <= n; i++) ans = max(ans,maxx[i]+a[i].f-ps[i-1]);
cout << ans << endl;
}
# | 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... |