#include <bits/stdc++.h>
#define ll long long
#define pr pair <ll, ll>
#define fi first
#define se second
using namespace std;
const int N = 5e5 + 5;
ll pre[N], n, res = -1e18;
pr a[N];
void inp()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i].fi >> a[i].se;
sort(a + 1, a + n + 1);
}
void solve()
{
for (int i = 1; i <= n; i++)
pre[i] = pre[i-1] + a[i].se;
ll _max = a[1].fi;
for (int i = 1; i <= n; i++)
{
res = max(res, pre[i] - a[i].fi + _max);
_max = max(_max, a[i].fi - pre[i-1]);
}
cout << res;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
inp();
solve();
}
| # | 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... |