#include <bits/stdc++.h>
using namespace std;
#define int long long
struct Line {
mutable int k, m, p;
bool operator<(const Line& o) const { return k < o.k; }
bool operator<(int x) const { return p < x; }
};
struct LineContainer : multiset<Line, less<>> {
// for doubles, use inf = 1/.0, div(a,b) = a / b
static const int inf = 5e18;// implement this
long double div(int a, int b) { // floored division
return (long double)((long double)(a)/ (long double)(b)) ;
}
bool isect(iterator x, iterator y) {
if (y == end()) return x->p = inf, 0;
if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
else x->p = div(y->m - x->m, x->k - y->k);
return x->p >= y->p;
}
void add(int k, int m) { // insert y = kx + m
auto z = insert({k, m, 0}), y = z++, x = y;
while (isect(y, z)) z = erase(z);
if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
while ((y = x) != begin() && (--x)->p >= y->p)
isect(x, erase(y));
}
int query(int x) { // max query
assert(!empty());
auto l = *lower_bound(x);
return l.k * x + l.m;
}
};
// to use:
// LineContainer hull;
// hull.add(m, c);
// hull.query(x);
// to convert max queries to min queries:
// hull.add(-m, -c);
// -hull.query(x);
int dp[1000005], P[1000005];
priority_queue<int>pq;
pair<int, int> A[1000005];
main(){
ios::sync_with_stdio(0);cin.tie(0);
int n;cin >> n;
for(int i=1;i<=n;i++){
cin >> A[i].first >> A[i].second;
}
sort(A+1, A+n+1);
int cnt = 0, ans = -1e17;
int in = 1;
for(int i=1;i<=n;i++){
cnt += A[i].second;
while(in < i && A[in+1].first - A[in].first > A[in].second)cnt -= A[in].second, in++;
ans = max(ans, cnt - A[i].first + A[in].first);
}
cout << ans;
}
Compilation message
art.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
46 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |