#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 500005
#define f first
#define s second
int tc = 1, n, ans = LLONG_MIN, p[N], S[N];
pair <int,int> a[N];
int32_t main() {
ios::sync_with_stdio(0);cin.tie(0);
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++) {
S[i] = a[i].s + S[i - 1];
p[i] = max(p[i - 1], a[i].f - S[i - 1]);
ans = max(ans,S[i] - a[i].f + p[i]);
}
cout << ans << '\n';
return 0;
}
| # | 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... |