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 namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<pair<long long, int>> v(n);
for (auto &p : v) {
cin >> p.first >> p.second;
}
sort(v.begin(), v.end());
long long ans = numeric_limits<long long>::min();
long long s = 0, mn = numeric_limits<long long>::max();
for (int i = 0; i < n; ++i) {
long long curr = s - v[i].first;
s += v[i].second;
mn = min(mn, curr);
ans = max(ans, s - mn - v[i].first);
}
cout << ans << endl;
}
# | 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... |