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>
#define fi first
#define se second
#define mp make_pair
using namespace std;
template <class X, class Y> bool minimize(X &a, Y b) {
if (a > b) return a = b, true;
return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
if (a < b) return a = b, true;
return false;
}
const int N = 5e5 + 7;
pair<long long, int> a[N];
long long pref[N];
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
for (int i = 1; i <= n; i ++) {
cin >> a[i].fi >> a[i].se;
}
sort(a + 1, a + n + 1);
long long res = 0, mx = 0;
for (int i = 1; i <= n; i ++) {
pref[i] = pref[i - 1] + a[i].se;
maximize(mx, -pref[i - 1] + a[i].fi);
maximize(res, pref[i] - a[i].fi + mx);
}
cout << res;
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... |