#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fst first
#define snd second
#define pb push_back
#define forn(i,a,b) for(int i = a; i<b; i++)
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset(a,v,sizeof(a))
#define FIN ios::sync_with_stdio(0); cout.tie(); cin.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
template <typename L>
using iset = tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update>;
int main(){
ll n; cin>>n;
vector<pair<ll,ll>> a(n); forn(i,0,n) cin>>a[i].fst>>a[i].snd;
sort(ALL(a));
ll res = 0;
ll mini=a[0].fst;
ll sum = 0;
forn(i,0,n){
sum+=a[i].snd;
res=max(res,sum-a[i].fst+mini);
if(i<n-1) mini=max(mini,-sum+a[i+1].fst);
}
cout<<res<<'\n';
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... |