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 ll = long long;
const int nmax = 500000;
std::pair<ll, ll> a[1 + nmax];
ll sp[1 + nmax];
int main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
int n;
std::cin >> n;
for(int i = 1; i <= n; i++)
std::cin >> a[i].first >> a[i].second;
std::sort(a + 1, a + n + 1, [&](const std::pair<ll, ll> &a, const std::pair<ll, ll> &b) -> bool {
return a.first < b.first;
});
for(int i = 1; i <= n; i++)
sp[i] = sp[i - 1] + a[i].second;
ll mn = (1LL << 60), mx = -(1LL << 60);
for(int i = 1; i <= n; i++) {
mn = std::min(mn, sp[i - 1] - a[i].first);
mx = std::max(mx, sp[i] - a[i].first - mn);
}
std::cout << mx;
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... |