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 ll long long
#define pb push_back
#define ull unsigned long long
#define fi first
#define se second
#define ld long double
ll n, sums;
pair<ll, ll>arr[100005];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i=1;i<=n;++i){
cin >> arr[i].fi >> arr[i].se;
sums+=arr[i].se;
}
sort(arr+1, arr+1+n);
ll l=1, r=n, maks=sums-(arr[n].fi-arr[1].fi);
while(l<r){
ll hapus_depan=(sums-arr[l].se)-(arr[r].fi-arr[l+1].fi);
ll hapus_blkg=(sums-arr[r].se)-(arr[r-1].fi-arr[l].fi);
if(hapus_depan > hapus_blkg){
maks=max(maks, hapus_depan);
sums-=arr[l].se;
l++;
}
else{
maks=max(maks, hapus_blkg);
sums-=arr[r].se;
r--;
}
}
cout << maks << '\n';
}
# | 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... |