This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define maxn 500005
#define pll pair<long long,long long>
#define f first
#define s second
using namespace std;
int n;
pll a[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n;
for(int i=0;i<n;i++)cin>>a[i].f>>a[i].s;
sort(a,a+n);
for(int i=1;i<n;i++)a[i].s+=a[i-1].s;
long long sol=a[0].s;
long long minn=-a[0].f;
for(int i=1;i<n;i++)
{
long long x=a[i].s-a[i].f;
if(a[i-1].s-a[i].f<minn)minn=a[i-1].s-a[i].f;
x-=minn;
if(sol<x)sol=x;
}
cout<<sol<<endl;
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... |