#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 5e5 + 2;
pair < ll, ll > P[N];
int main() {
ll n, m, r, x, y, i, j, mn, ans, t, mx;
cin >> n;
for (i = 1; i <= n; i ++) {
cin >> P[i].first >> P[i].second;
}
sort ( P + 1, P + n + 1);
ll pre[n+ 2];
ll a[n +2 ], b[n + 2];
pre[0] = 0;
for (i = 1; i <= n; i ++) {
pre[i] = pre[i - 1] +P[i].second;
}
for (i =1; i <= n; i ++) {
a[i] = pre[i] - P[i].first ;
b[i] = pre[i - 1] - P[i].first;
}
ans =0;
mn = LONG_MAX;
for (i = 1; i <= n; i ++) {
mn = min(mn, b[i]);
ans = max(ans, a[i] - mn);
}
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... |