이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//In the name of Allah
//Ya Ali!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll maxn = 5000 * 101 ;
const ll INF = 1e18 ;
#define f first
#define s second
ll n , pre[maxn] , ans = 0 , maxx = 0 ;
vector<pair<ll,ll> > v ;
int main()
{
std::ios::sync_with_stdio(0) ;
cin.tie(0) ;
cout.tie(0) ;
cin >> n ;
for(int  i = 0 ; i < n ; i ++){
    ll a , b ;
    cin >> a >> b ;
    v.push_back({a,b}) ;
}
sort(v.begin() , v.end()) ;
pre[0] = v[0].s ;
for(int i = 1 ; i < n ;i ++)pre[i] = pre[i-1] + v[i].s ;
ans = pre[0] - v[0].f ;
maxx = v[0].f ;
for(int i = 1 ; i < n ; i ++){
    maxx = max(maxx , v[i].f - pre[i-1]) ;
    ans = max(ans , pre[i] - v[i].f + maxx) ;
}
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... |