#include <bits/stdc++.h>
using namespace std;
#define int long long
#define run ios_base::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
#define endl '\n'
const int inf = 1e18+7;
const int sz = 1e5+5;
void solve() {
int n;
cin >> n;
pair<int,int> a[n+1];
for(int i = 1; i <= n;i++) cin >> a[i].F >> a[i].S;
sort(a+1,a+n+1);
int psum[n+1];
psum[0] = 0;
psum[1] = a[1].S;
for(int i = 1; i <= n;i++){
psum[i] = psum[i-1] + a[i].S;
}
int best = -1;
for(int i = 1; i <= n;i++){
int mx = -1,mn = inf,cost = 0,sum=0;
mn = a[i].F;
for(int j = i;j <= n;j++){
mx = max(a[j].F,mx);
sum = psum[j] - psum[i-1];
cost = sum - mx + mn;
best = max(cost,best);
}
}
cout << best << endl;
}
signed main() {
run;
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}
// 11111100000
# | 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... |