#include "bits/stdc++.h"
#define endl '\n'
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<int>::iterator vit;
typedef set<int> si;
typedef map<int, int> mii;
void solve() {
ll n, a, b;
cin >> n;
vector<pair<ll, ll>> art(n);
for (auto &x : art)
cin >> x.first >> x.second;
sort(all(art));
ll mx = 0;
vl pre(n + 1);
pre[0] = 0;
for (ll i = 0; i < n; i++) {
mx = max(mx, art[i].second);
pre[i + 1] = pre[i] + art[i].second;
}
ll run_min = 0;
for(ll i =1; i<=n;i++){
mx= max(mx, pre[i]-art[i-1].first +run_min) ;
run_min = max(run_min, art[i-1].first-pre[i-1]);
}
cout << mx << endl;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
unsigned long long ct = 1;
// cin >> ct;
while (ct--)
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... |