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;
#define endl '\n'
#define mod 1000000007
#define ll long long
#define inf 1000000009
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll a; cin>>a;
pair<ll,ll> p[a+1];
p[0].first=-1;
p[0].second=-1;
for(int i=1;i<=a;i++){
cin>>p[i].first; cin>>p[i].second;
}
sort(p,p+a+1);
ll pref[a+1],prefmn[a+1];
pref[0]=0;
prefmn[0]=1e9;
for(int i=1;i<=a;i++){
pref[i]=p[i].second+pref[i-1];
prefmn[i]=min(prefmn[i-1],p[i].first*-1+pref[i-1]);
}
ll mx=0;
for(int i=1;i<=a;i++){
mx=max(mx,pref[i]-p[i].first-prefmn[i]);
}
cout<<mx;
}
# | 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... |