#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair <ll, ll> pii;
#define fi first
#define se second
#define pb push_back
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; cin >>n;
vector <pii> v;
v.pb({0, 0});
for(int i = 1 ; i <= n ; i++){
int a, b; cin >> a >> b;
v.pb({a, b});
}
sort(v.begin(), v.end());
ll pref[5005];
pref[0] = 0;
for(int i = 1 ; i <= n ; i++)pref[i] = pref[i - 1] + v[i].se;
ll ans = 0;
for(int i = 1 ; i <= n; i++){
for(int j = i ; j <= n ; j++){
ans = max(ans, pref[j] - pref[i - 1] - v[j].fi + v[i].fi);
}
}
cout << ans << endl;
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... |