#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<long long, long long>> q;
for (int i = 0; i < n; ++i) {
long long a, b;
cin >> a >> b;
q.push_back({a, b});
}
sort(q.begin(), q.end());
long long ans = -1;
long long cur = q[0].second;
long long check = q[0].second;
for (int i = 1; i < n; ++i) {
cur += q[i].second - (q[i].first - q[0].first);
if (i > 1) {
cur += (q[i - 1].first - q[0].first);
}
ans = max(ans, cur);
check = max(check, q[i].second);
}
cout << max(ans, max(check, 0LL)) << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |