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 ll long long
using namespace std;
const int inf = 5e5+9;
ll n,pre[inf],ans,mn;
pair<ll,ll> a[inf];
int main(){
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i].first>>a[i].second;
sort(a+1,a+1+n);
pre[1] = ans = a[1].second;
mn = -a[1].first;
for(int i=2;i<=n;i++){
pre[i] = pre[i-1] + a[i].second;
ans = max(ans, pre[i] - a[i].first - mn);
mn = min(mn,pre[i-1] - a[i].first);
}
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... |