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>
typedef long long ll;
using namespace std;
const ll maxN = 5e5+10;
pair<ll, ll> a[maxN];
ll maxVal=0;
void check(ll mn, ll mx, ll s){
maxVal=max(maxVal, s-abs(mn-mx));
}
int main()
{
ios_base::sync_with_stdio();cin.tie(nullptr);
ll n;
cin>>n;
for(int i = 0; i < n; i++){
ll aa, bb;
cin>>aa>>bb;
a[i]={aa, bb};
}
sort(a, a+n);
for(int i = 0; i < n; i++){
ll mnS=a[i].first;
ll mxS=a[i].first;
ll s = a[i].second;
check(mnS, mxS, s);
for(int x = i+1; x < n; x++){
s+=a[x].second;
mnS=min(mnS, a[x].first);
mxS=max(mxS, a[x].first);
check(mnS, mxS, s);
}
}
cout<<maxVal;
return 0;
}
# | 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... |