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;
typedef pair<int64_t,int64_t> ii;
int64_t n,s[500005];
ii a[500005];
int main()
{
cin>>n;
for(int64_t i=1;i<=n;i++)
cin>>a[i].first>>a[i].second;
sort(a+1,a+n+1);
for(int64_t i=1;i<=n;i++)
s[i]=s[i-1]+a[i].second;
int64_t maxn=-1e18,res=-1e18;
for(int64_t i=1;i<=n;i++)
{
maxn=max(maxn,a[i].first-s[i-1]);
res=max(res,s[i]-a[i].first+maxn);
}
cout<<res;
}
# | 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... |