#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
typedef pair<int,int> pii;
const int N = 5e5+5;
int s[N], v[N], p[N], dp[N];
pii arr[N];
signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	for(int i=1; i<=n; i++){
		int a,b; cin>>a>>b;
		arr[i] = {a,b};
	}
	sort(arr+1, arr+1+n);
	
	for(int i=1; i<=n; i++) p[i] = p[i-1] + arr[i].se;
	int mi = -arr[1].fi;
	for(int i=1; i<=n; i++){
		dp[i] = p[i] - arr[i].fi - mi;
		mi = min(mi, p[i]-arr[i+1].fi);
	}
	
	int ans = 0;
	for(int i=1; i<=n; i++) ans = max(ans, dp[i]);
	cout<<ans;
	
	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... |