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;
typedef long long int ll;
const int MOD = 1e9 + 7;
void solve(){
int n; cin >> n;
vector<pair<ll, ll>> v(n);
for(int i = 0; i < n; i++){
ll a, b; cin >> a >> b; v[i] = {a, b};
}
sort(v.begin(), v.end());
ll sum = 0;
ll mx = 0;
ll ans = 0;
for(int i = 0; i < n; i++){
if(i == 0){
mx = max(mx, v[i].first);
ans = max(ans, v[i].second);
sum += v[i].second;
continue;
}
ans = max(ans, sum + v[i].second + mx - v[i].first);
mx = max(mx, -sum + v[i].first);
sum += v[i].second;
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//~ int tt; cin >> tt;
int tt = 1;
for(int t = 1; t <= tt; 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... |