#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1'000'000'000'000'000'000LL;
const int II = 2'000'000'000;
const ll M = 1'000'000'007LL;
const int N = 1'000'007;
pair<ll, int> tab[N];
void Solve()
{
int n;
cin >> n;
for(int i = 1; i <= n; ++i)
cin >> tab[i].st >> tab[i].nd;
sort(tab + 1, tab + 1 + n);
ll cur = 0LL, ma = -I, ans = -I;
for(int i = 1; i <= n; ++i)
{
ma = max(ma, -cur + tab[i].st);
cur += tab[i].nd;
ans = max(ans, cur - tab[i].st + ma);
}
cout << ans << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//int t; cin >> t;
//while(t--)
Solve();
return 0;
}
# | 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... |