// created : 2026/02/08 18:40:30
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(v) v.begin(), v.end()
void solve() {
int n; cin >> n;
vector<pair<int, int>> vt;
for(int i = 0; i < n; i++) {
int x, y; cin >> x >> y;
vt.pb({x, y});
}
sort(all(vt));
int maxi = 0;
for(int i = 0; i < n; i++) {
int sum = 0, a = LLONG_MIN, b = LLONG_MAX;
for(int j = i; j < n; j++) {
a = max(vt[j].first, a), b = min(vt[j].first, b);
sum += vt[j].second;
maxi = max(sum - (a - b), maxi);
}
}
cout << maxi << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
//cin >> t;
while (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... |