#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MAX=5*1e3+7;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
ll a, b, cale=0, mmin=1e16, mmax=0;
vector<pair<ll, ll>> prace;
for (int i=0; i<n; i++){
cin >> a >> b;
cale += b;
mmin = min(mmin, a);
mmax = max(mmax, a);
prace.push_back({a, b});
}
cale -= (mmax-mmin);
sort(prace.begin(), prace.end());
pair<ll, ll> pref[MAX];
pair<ll, ll> suf[MAX];
pref[0] = {0, 0};
for (int i=1; i<n; i++){
pref[i].first = pref[i-1].first - prace[i-1].second+(prace[i].first-prace[i-1].first);
pref[i].second = max(pref[i].first, pref[i-1].second);
}
suf[n] = {0, 0};
for (int i=n-2; i>0; i--){
suf[i].first = suf[i+1].first - prace[i+1].second+(prace[i+1].first-prace[i].first);
suf[i].second = max(suf[i].first, suf[i+1].second);
}
ll wyn=0;
for (int i=0; i<n; i++){
wyn = max(wyn, pref[i].second+suf[i].second);
}
cout << cale << " " << wyn << endl;
cout << cale+wyn << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |