#include <bits/stdc++.h>
#include <random>
using namespace std;
using ll = long long;
using ld = long double;
ll INF = 1e18 + 10;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll n;
cin >> n;
vector<pair<ll, ll>> s(n);
ll ans = -INF;
for (ll i = 0; i < n; i++) {
cin >> s[i].first >> s[i].second;
ans = max(ans, s[i].second);
}
std::sort(s.begin(), s.end());
vector<ll> pref(n + 1);
for (ll i = 0; i < n; i++) {
pref[i + 1] = pref[i] + s[i].second;
}
ll mx = pref[n] - s[n - 1].first;
for (ll j = n - 2; j >= 0; j--) {
ans = max(ans, mx - pref[j] + s[j].first);
mx = max(mx, pref[j + 1] - s[j].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... |