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;
long long n,l;
long long ans,b[500005],mx[500005],ps[500005];
pair<long long,long long> a[500005];
int main(){
ios::sync_with_stdio(false);
cin >> n;
for (int i=1;i<=n;i++){
cin >> a[i].first >> a[i].second;
}
sort(a+1,a+1+n);
for (int i=1;i<=n;i++){
ps[i]=ps[i-1]+a[i].second;
b[i]=ps[i]-a[i].first;
}
mx[n+1]=-1e18;
for (int i=n;i>=1;i--){
mx[i]=max(mx[i+1],b[i]);
}
ans=-1e18;
for (int i=1;i<=n;i++){
ans=max(ans,mx[i]+a[i].first-ps[i-1]);
}
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... |