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>
using namespace std;
const long long mod=998244353;
long long n,ps[500005];
pair<long long,long long>a[500005];
multiset<long long>ms;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i].first>>a[i].second;
}
sort(a,a+n);
for(int i=0;i<n;i++)
{
ps[i]=ps[i-1]+a[i].second;
ms.insert(ps[i]-a[i].first);
}
long long ans=0;
for(int i=0;i<n;i++)
{
ans=max(ans,*--ms.end()+a[i].first-ps[i-1]);
ms.erase(ms.find(ps[i]-a[i].first));
}
cout<<ans;
}
# | 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... |