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 ll long long
#define pii pair <ll, ll>
#define st first
#define nd second
#define rep(i, n, m) for (ll i = (n); i <= (m); i ++)
#define rrep(i, m, n) for (ll i = (m); i >= (n); i --)
using namespace std;
const long long N = 2e5 + 5;
ll n, f[N];
pii a[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
rep(i, 1, n) cin >> a[i].st >> a[i].nd;
sort(a + 1, a + 1 + n);
ll ans = 0;
ll mi = -a[1].st;
rep(i, 1, n) {
f[i] = f[i - 1] + a[i].nd;
ll p = f[i] - a[i].st;
ans = max(ans, p - mi);
mi = min(mi, f[i] - a[i + 1].st);
}
cout << ans;
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... |