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;
using ll = long long;
int main()
{
int n;
cin >> n;
vector<pair<ll, ll>> sv;
ll suma = 0;
sv.push_back({0, 0});
for(int i = 0; i < n; ++i)
{
ll a, b;
cin >> a >> b;
suma += b;
sv.push_back({a, b});
}
sort(sv.begin(), sv.end());
sv.push_back({0, 0});
ll sp[n+1];
sp[0] = 0;
for(int i = 1; i <= n; ++i)
sp[i] = sp[i-1] + sv[i].second - (sv[i+1].first - sv[i].first);
ll mi = 0;
ll odp = 0;
for(int i = 1; i <= n; ++i)
{
odp = max(odp, sp[i]-mi+(sv[i+1].first - sv[i].first));
mi = min(mi, sp[i]);
}
cout << odp;
}
# | 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... |