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 oo 1e9
#define pii pair<ll, ll>
using namespace std;
int main()
{
int n; cin >> n;
pii arr[n + 1];
arr[0] = {0, 0};
for (int i = 1; i <= n; i++)
{
cin >> arr[i].first >> arr[i].second;
}
sort(arr, arr + n + 1);
ll pre[n + 1];
pre[0] = 0;
for (int i = 1; i <= n; i++)
{
pre[i] = pre[i - 1] + arr[i].second;
}
multiset<ll> s;
for (int i = 1; i <= n; i++)
{
s.insert(pre[i] - arr[i].first);
}
ll ans = 0;
for (int i = 1; i <= n; i++)
{
auto itr = prev(s.end());
ans = max(ans, (*itr) - pre[i - 1] + arr[i].first);
s.erase(s.find(pre[i] - arr[i].first));
}
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... |