#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
const int N = 5e5 + 5;
pii a[N];
int pre[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].fi >> a[i].se;
sort(a + 1,a + n + 1);
for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i].se;
int mini = -a[1].fi,ans = 0;
for (int i = 1; i <= n; i++) {
ans = max(ans,pre[i] - a[i].fi - mini);
mini = min(mini,pre[i] - a[i + 1].fi);
}
cout << ans << "\n";
}
# | 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... |