#include <iostream>
#include <vector>
#include <algorithm>
long long sum(long long i, long long j, std::vector<long long>& PS) {
return PS[j] - (i == 0 ? 0 : PS[i - 1]);
}
int main()
{
long long N;
std::cin >> N;
std::vector<std::pair<long long, long long>> P(N);
for (auto& [a, b] : P) {
std::cin >> a >> b;
}
std::sort(P.begin(), P.end());
std::vector<long long> D(N);
D[0] = P[0].second;
for (long long i = 1; i < N; i++) {
D[i] = P[i].second - (P[i].first - P[i - 1].first);
}
std::vector<long long> PS(N);
PS[0] = D[0];
for (long long i = 1; i < N; i++) {
PS[i] = PS[i - 1] + D[i];
}
long long result = 0;
long long i = 0, j = 0;
long long cur = P[0].second;
while (j < N) {
cur = sum(i, j, PS);
result = std::max(result, cur);
while (cur < 0 && i < j) {
i++;
cur = sum(i, j, PS);
result = std::max(result, cur);
}
j++;
}
while (i < N) {
result = std::max(result, sum(i, N - 1, PS));
i++;
}
std::cout << result << std::endl;
}
Compilation message
art.cpp: In function 'int main()':
art.cpp:16:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
16 | for (auto& [a, b] : P) {
| ^
# |
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 |
- |