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;
#define int long long
#define pii pair<long long, long long>
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<pii> ab(n);
for (int i = 0; i < n; i++) cin >> ab[i].first >> ab[i].second;
sort(ab.begin(), ab.end());
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
a[i] = ab[i].first;
b[i] = ab[i].second;
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
int tans = 0, mn = 1e16, mx = -1e16;
for (int k = i; k <= j; k++) {
tans += b[k];
mn = min(mn, a[k]);
mx = max(mx, a[k]);
}
ans = max(ans, tans - mx + mn);
}
}
cout << ans << "\n";
}
# | 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... |