#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<pair<long long, long long>> a(n);
for (int i = 0; i < n; i++)
{
cin >> a[i].first >> a[i].second;
}
sort(a.begin(), a.end(), [](auto &x, auto &y)
{
return x.first < y.first;
});
long long res = LLONG_MIN;
long long m = a[0].first;
long long pf = 0;
for (int i = 0; i < n; i++)
{
pf += a[i].second;
long long mk = pf - a[i].first + m;
res = max(res, mk);
if (i + 1 < n)
{
m = max(m, a[i + 1].first - pf);
}
}
cout << res;
}
# | 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... |