#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x)(x).begin(), (x).end()
#define F first
#define S second
#define nn '\n'
#define pb push_back
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].F >> a[i].S;
}
sort(all(a));
int l = 0, sum = 0, ans = -1;
for (int r = 0; r < n; r++) {
sum += a[r].S;
while (l < r && sum - (a[r].F - a[l].F) < (sum - a[l].S + a[l + 1].S)- (a[r].F - a[l + 1].F)) {
sum -= a[l].S;
l++;
}
ans = max(ans, sum + a[l - 1].S - (a[r].F - a[l].F));
}
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... |