This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I'm back in action
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define pb push_back
#define forn(i, n) for (int i = 0; i < n; i++)
int32_t main() {
int n;
cin >> n;
vector<pair<int, int>> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i].f >> a[i].s;
}
sort(a.begin() + 1, a.end());
vector<int> pref(n + 1);
for (int i = 1; i <= n; i++) {
pref[i] = pref[i - 1] + a[i].s;
}
int ans = -1e18;
int mx = -1e18;
for (int r = 1; r <= n; r++) {
mx = max(mx, a[r].f - pref[r - 1]);
ans = max(ans, pref[r] - a[r].f + mx);
}
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... |