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 ll long long
int main() {
int n;
cin >> n;
pair<ll, ll> a[n];
for (int i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a, a + n);
ll mini = -a[0].first, maxi = -1e18;
ll ans = 0;
ll ps = 0;
ll cur;
for (int i = 0; i < n; i++) {
ps += a[i].second;
cur = ps - a[i].first;
if (cur > maxi) {
maxi = cur;
ans = max(ans, maxi - mini);
}
if (i + 1 < n) {
cur = ps - a[i + 1].first;
if (cur < mini) mini = cur;
}
}
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... |