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>
typedef long long ll;
int main() {
std::ios::sync_with_stdio(0); std::cin.tie(0);
int n; std::cin >> n;
std::vector <std::pair <ll, ll>> a(n);
for (auto& p : a) std::cin >> p.first >> p.second;
std::sort(a.begin(), a.end());
ll ans = a[0].second;
for (ll i = 0, sum = 0, max = a[0].first; (int)i < n; i++) {
sum += a[i].second;
max = std::max(max, a[i].first - sum + a[i].second);
ans = std::max(ans, sum + max - a[i].first);
}
std::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... |