#include<bits/stdc++.h>
using namespace std;
int n;
vector<long long> p;
vector<pair<long long, int>> a;
int main()
{
cin >> n;
for(int i = 1; i <= n; i ++){
int y;
long long x;
cin >> x >> y;
a.push_back({x, y});
}
sort(a.begin(), a.end());
p.resize(n, 0ll);
for(int i = 0; i < n; i ++){
if(i > 0) p[i] = p[i - 1];
p[i] += a[i].second;
}
long long mx = 0ll;
for(int i = 0; i < n; i ++){
int l = 0, r = i;
while(l < r){
int m = (l + r) / 2;
long long sum = p[i];
if(m > 0) sum -= p[m - 1];
if(sum - (a[i].first - a[m].first) >= a[i].second){
r = m;
}
else{
l = m + 1;
}
}
long long sum = p[i];
if(l > 0) sum -= p[l - 1];
mx = max(mx, sum - (a[i].first - a[l].first));
}
cout << mx << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
368 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
4 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
368 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
4 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
368 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
4 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
368 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
4 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |