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;
typedef long long ll;
ll N;
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> N;
vector<pair<ll, ll>> v;
v.push_back({0, 0});
for(int i = 0; i < N; i++) {
ll w, x;
cin >> w >> x;
v.push_back({w, x});
}
sort(v.begin(), v.end());
vector<ll> pref(N + 1);
for(int i = 1; i <= N; i++) pref[i] = pref[i - 1] + v[i].second;
for(int i = 0; i < N; i++) pref[i] -= v[i + 1].first;
ll opt = pref[0], s = 0, ans = 0;
for(int i = 1; i <= N; i++) {
s += v[i].second;
ans = max(ans, s - opt - v[i].first);
opt = min(opt, pref[i]);
}
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... |