#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
vector <array <int, 2>> v(n);
for (auto& e : v) {
cin >> e[0] >> e[1];
}
sort(begin(v), end(v));
vector <array <int, 2>> r;
int sm = v[0][1];
for (int i = 1; i < n; i ++) {
if (v[i][0] != v[i - 1][0]) {
r.push_back({v[i - 1][0], sm});
sm = v[i][1];
} else {
sm += v[i][1];
}
}
r.push_back({v.back()[0], sm});
int m = r.size();
int le, ri, mx, it, in;
le = ri = mx = sm = 0;
for (; ri < m; ri ++) {
mx = max(mx, r[ri][1]);
sm += r[ri][1];
it = sm - r[ri][0] + r[le][0];
in = sm - r[le][1] - r[ri][0] - r[le + 1][0];
for (; it < in && le < ri - 1; le ++) {
sm -= r[le][1];
it = sm - r[ri][0] + r[le][0];
in = sm - r[le][1] - r[ri][0] - r[le + 1][0];
}
mx = max(mx, sm - (r[ri][0] - r[le][0]));
}
cout << mx << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 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 |
344 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 |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |