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 f first
#define s second
#define pb push_back
using namespace std;
const int N=5e5+5;
long long n,pr[N],ans,mn;
pair <long long , long long> a[N];
int main() {
cin>>n;
for (int i=1; i<=n; i++) {
cin>>a[i].f>>a[i].s;
}
sort(a+1, a+n+1);
for (int i=1; i<=n; i++) {
pr[i]=pr[i-1]+a[i].s;
}
ans=0;
mn=-a[1].f;
for (int i=1; i<=n; i++) {
// cout<<i<<" "<<pr[i]-a[i].f<<" "<<mn<<endl;
ans=max(ans, pr[i]-a[i].f-mn);
mn=min(mn,pr[i]-a[i+1].f);
}
cout<<ans<<endl;
}
# | 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... |