#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
const int N = 5e5 + 5,
INF = 1e9;
int n, dp[N], pref[N];
ii a[N];
int32_t main(){
cin.tie(0)->sync_with_stdio(0);
// #define task "test"
// if(fopen(task ".inp", "r")){
// freopen(task ".inp", "r", stdin);
// freopen(task ".out", "w", stdout);
// }
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i].second;
int res = 0, d = a[1].first - pref[0];
for(int i = 2; i <= n; i++){
res = max(res, pref[i] - a[i].first + d);
d = max(d, a[i].first - pref[i - 1]);
}
for(int i = 1; i <= n; i++) res = max(res, a[i].second);
cout << res << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |