#include<bits/stdc++.h>
using namespace std;
#define int long long
int s[500001];
int main(){
int n, ans = 0,maxx = 0; cin >> n;
pair<int, int> p[n+1];
s[0] = 0;
for(int i = 1; i <= n; i++){
cin >> p[i].first >> p[i].second;
s[i] = 0;
}
sort(p+1, p+n+1);
for (int i = 1; i <= n; i++)
s[i] = s[i - 1] + p[i].second;
for(int i = 1; i <= n; i++){
maxx = max(maxx, p[i].first - s[i - 1]);
ans = max(ans, s[i] + maxx - p[i].first);
}
cout << ans << endl;
}
Compilation message
cc1plus: error: '::main' must return 'int'