This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
Sopaconk
*/
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define deb(x) cout<<#x<<": "<<(x)<<endl
using lli=long long int;
//using pii=pair<int,int>;
using ld=long double;
lli MOD=1e9+7;
using namespace std;
#define endl '\n'
void solve(){
lli n;
cin>>n;
vector<pair<lli,lli>> v (n);
lli ans=0;
for(lli i=0; i<n; ++i){
lli a,b;
cin>>a>>b;
ans=max(ans, b);
v[i]={a,b};
}
sort(v.begin(), v.end());
vector<lli> sums (n+1,0);
vector<lli> val (n+1,0);
vector<lli> maxiv(n+1,0);
for(lli i=n-1; i>=0; --i){
sums[i]=sums[i+1]+v[i].second;
val[i]=sums[i]+v[i].first;
}
maxiv[0]=val[0];
for(lli i=1; i<n; ++i){
maxiv[i]=max(val[i], maxiv[i-1]);
}
for(lli i=1; i<n; ++i){
lli si=maxiv[i-1]-sums[i+1]-v[i].first;
ans=max(ans, si);
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
}
# | 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... |