#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define fi first
#define se second
const int N = 5e5+3;
pair<int, int> f[N];
int st[N<<2];
void update(int id, int l, int r, int p, int v)
{
if(p<l || r<p) return;
if(l==r)
{
st[id]=v;
return;
}
int mid=(l+r)>>1;
update(id<<1, l, mid, p, v);
update(id<<1 | 1, mid+1, r, p, v);
st[id]=max(st[id<<1], st[id<<1 | 1]);
}
int get(int id, int l, int r, int x, int y)
{
if(y<l || r<x) return LLONG_MIN;
if(x<=l && r<=y) return st[id];
int mid=(l+r)>>1;
return max(get(id<<1, l, mid, x, y), get(id<<1 | 1, mid+1, r, x, y));
}
void solve()
{
int n,ans=LLONG_MIN;
cin>>n;
f[0]={0,0};
for(int i=1; i<=n; i++) cin>>f[i].fi>>f[i].se;
sort(f+1, f+1+n);
for(int i=1; i<=n; i++)
{
f[i].se += f[i-1].se;
ans=max(ans, f[i].se - f[i].fi + (i>1 ? get(1, 1, n, 1, i-1) : 0));
update(1, 1, n, i, f[i].fi - f[i-1].se);
}
cout<<ans;
}
signed main()
{
fast
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |