#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int int_fast32_t
#define ul uint_fast32_t
#define ll int_fast64_t
#define dll long double
#define ull uint_fast64_t
#define spektar this_thread::sleep_for(chrono::milliseconds(50))
void solve(){
int n;
cin >> n;
vector<array<ll,2>> k(n);
for(auto& [a,b]:k) cin >> a >> b;
sort(k.begin(),k.end());
vector<ll> pref(n+1);
pref[0]=-k[0][0];
ll min1=1000000000000000000;
ll s=0;
ll max1=0;
for(int i=0; i<n; i++){
s+=k[i][1];
max1=max(max1,s-k[i][0]-min1);
if(i<n-1){
min1=min(min1,pref[i]);
pref[i]=s-k[i+1][0];
}
}
cout << max1 << endl;
}
signed main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
//cin >> t;
while(t--){
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... |