#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];
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)
{
while(j<i&&a[j].se<a[j+1].fi-a[j].fi)
{
j++;
}
d=max(d,f[i]-f[j-1]-(a[i].fi-a[j].fi));
}
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... |