#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, l=1, r=1, sum, ans;
pair<int, int> arr[100010];
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i=1; i<=n; i++) {
cin >> arr[i].first >> arr[i].second;
}
sort(arr+1, arr+n+1);
sum = arr[1].second;
ans = max(ans, sum);
while(true) {
while(l < r && arr[l].second <= arr[l+1].first-arr[l].first) {
sum += arr[l+1].first-arr[l].first-arr[l].second;
l++;
}
ans = max(ans, sum);
if(r == n) break;
r++;
sum += arr[r].second - arr[r].first + arr[r-1].first;
if(sum < 0) {
l = r+1;
r++;
sum = arr[r].second;
}
ans = max(ans, sum);
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |