#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<pair<int,int>> a(n + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a.begin() + 1, a.end());
vector<int> pref(n + 1, 0);
vector<int> suf(n + 2, -1e18);
for(int i = 1; i <= n; i++) {
pref[i] = pref[i - 1] + a[i].second;
}
for(int i = n; i >= 1; i--) {
suf[i] = max(pref[i] - a[i].first, suf[i + 1]);
}
int ans = 0;
for(int i = 1; i < n; i++) {
ans = max(ans, suf[i] - pref[i - 1] + a[i].first);
}
cout << ans;
}
# | 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... |