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;
pair<long long,long long>p[500005];
int n;
long long ans=-1e18;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>p[i].first>>p[i].second;
sort(p+1,p+n+1);
long long tong=0;
long long minn=0;
for(int i=1;i<=n;i++)ans=max(ans,p[i].second);
minn=min(minn,-p[1].first);
tong+=p[1].second;
for(int i=2;i<=n;i++)
{
ans=max(ans,tong+p[i].second-p[i].first-minn);
minn=min(minn,tong-p[i].first);
tong+=p[i].second;
}
cout<<ans<<'\n';
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... |