#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 5e5 + 10;
ll a[maxn], p[maxn];
int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
freopen("in", "r", stdin);
#endif
int n; cin >> n;
vector<pair<ll, ll> > x(n);
for(int i = 0; i < n; i++) {
cin >> x[i].first >> x[i].second;
}
sort(x.begin(), x.end());
for(int i = 0; i < n; i++) {
a[i] = x[i].first;
}
p[0] = x[0].second;
for(int i = 1; i < n; i++)
p[i] = p[i - 1] + x[i].second;
// p[i] - p[j - 1] - a[i] + a[j]
//=p[i] - a[i] + (a[j] - p[j - 1])
ll ans = p[0] - a[0], Max = a[0];
for(int i = 1; i < n; i++) {
ans = max(ans, p[i] - a[i] + Max);
Max = max(Max, a[i] - p[i - 1]);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |