#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i = a; i <= b; ++i)
#define ff(i, a, b) for(ll i = a; i < b; ++i)
#define F(i, a, b) for(ll i = a; i >= b; --i)
#define FF(i, a, b) for(ll i = a; i > b; --i)
#define x first
#define y second
#define X real()
#define Y imag()
using namespace std;
typedef complex<ll> P;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
const int N = 5e5+7;
ll n, ans = 0, b[N], f[N], rmq[N][19];
ii a[N];
ll get_min(ll post){
ll loga;
if(loga > 1) loga = log2(post-1);
else loga = 0;
return min(rmq[0][loga], rmq[post-(1<<loga)][loga]);
}
signed main(){
// freopen("PERFECT1.inp","r",stdin);
// freopen("PERFECT1.out","w",stdout);
scanf("%lld", &n);
f(i,1,n){
scanf("%lld %lld", &a[i].x, &a[i].y);
}
sort(a+1, a+1+n);
rmq[0][0] = -a[1].x;
f(i,1,n){
f[i] = f[i-1] + a[i].y;
b[i] = f[i]-a[i].x;
if(i != n){
rmq[i][0] = f[i]-a[i+1].x;
}
}
f(j,1,18){
ff(i,0,n){
if(i + (1<<j) - 1 < n){
rmq[i][j] = min(rmq[i][j-1], rmq[i+(1<<(j-1))][j-1]);
}
}
}
f(i,1,n){
ans = max(ans, b[i]-get_min(i));
}
printf("%lld", ans);
}
Compilation message
art.cpp: In function 'int main()':
art.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &n);
~~~~~^~~~~~~~~~~~
art.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &a[i].x, &a[i].y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
art.cpp: In function 'long long int get_min(long long int)':
art.cpp:22:2: warning: 'loga' is used uninitialized in this function [-Wuninitialized]
if(loga > 1) loga = log2(post-1);
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |