#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#pragma ("reroll")
#define skip continue;
#define gold ios_base::sync_with_stdio(false);cin.tie(NULL);
#define xa "\n"
#define int long long
#define all(a) a.begin(), a.end()
#define pb push_back
#define F first
#define S second
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 7;
const int MAX = 1e9;
const int inf = 1e18;
int gcd(int a, int b) { if (b == 0) return a; else if(a == 0) return b; else return gcd(b, a % b); }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int pref[N];
void solve() {
int n;
cin >> n;
vector < pair < int, int > > v;
v.pb({-inf, -inf});
for(int i = 1; i <= n; i++){
int a, b;
cin >> a >> b;
v.pb({a, b});
}
sort(all(v));
for(int i = 1; i <= n; i++){
pref[i] = pref[i - 1] + v[i].S;
}
int mx = 0;
int ans = 0;
for(int r = 1; r <= n; r++){
mx = max(mx, v[r].F - pref[r - 1]);
ans = max(ans, pref[r] - v[r].F + mx);
}
cout << ans;
}
// p[r] - p[l - 1] - (a[r] - a[l]);
// (p[r] - a[r]) + (a[l] - p[l - 1]);
signed main() {
gold;
//freopen("pails.in", "r", stdin);
//freopen("pails.out", "w", stdout);
int t = 1;
int ti = 1;
//cin >> t;
while (t--) {
//cout << "Case " << ti << ": ";
solve();
ti++;
}
}
# | 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... |