#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define nmax 1000007
#define fi first
#define se second
#define ll long long
ll t=1,n,m,i,j,d=0,x=0,k=0,y,z,f[nmax],b[nmax],h[nmax],h1[nmax];
pair<ll,ll>a[nmax];
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
for(i=1;i<=n;++i)
{
cin>>a[i].fi>>a[i].se;
}
sort(a+1,a+n+1);
for(i=1;i<=n;++i)
{
f[i]=f[i-1]+a[i].se;
}
j=1;
d=0;
for(i=1;i<n;++i)
{
b[i]=a[i+1].fi-a[i].fi-a[i].se;
h[i]=max(0LL,h[i-1]+b[i]);
h1[i]=max(h1[i-1],h[i]);
}
for(i=1;i<=n;++i)
{
d=max(d,f[i]-a[i].fi+a[1].fi+h1[i-1]);
}
cout<<d;
}
| # | 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... |