#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define BIT(mask, x) ((mask >> (x)) & 1)
#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
cerr << t;
if (sizeof...(v)) cerr << ", ";
_print(v...);
}
#define dbg(x...) cerr << "[" << #x << "] = [", _print(x)
// -------------------------------------- CON CUA BO HCN --------------------------------------
const int maxn = 5e5 + 3;
int n;
pll a[maxn];
// --------------------------------------------------------------------------------------------
void solve()
{
cin >> n;
FOR(i, 1, n) cin >> a[i].first >> a[i].second;
sort(a + 1, a + n + 1);
ll mi = 1e18, res = -1e18, pre = 0;
FOR(i, 1, n)
{
mi = min(mi, pre - a[i].first);
pre += a[i].second;
// dbg(i, pre, mi);
res = max(res, pre - mi - a[i].first);
}
cout << res;
}
signed main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define TASK "TEST"
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
solve();
return 0;
}
/* NOTES:
*/
컴파일 시 표준 에러 (stderr) 메시지
art.cpp: In function 'int main()':
art.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
art.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
55 | freopen(TASK".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |