This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define pb push_back
#define mt make_tuple
const ll INF = 0x3f3f3f3f;
const ll inf = pow(10,18);
ll modulo = 998244353;
void deal(){
ll n;
cin>>n;
vector<pair<ll, ll> > arr;
fori(n){
ll ai, si;
cin>>ai>>si;
arr.pb(mp(ai, si));
}
sort(arr.begin(), arr.end());
ll mx = -inf;
ll pf = 0;
ll ans = 0;
for(auto& el : arr){
ll vl = pf-el.ff;
mx = max(mx, -vl);
pf+=el.ss;
vl = pf-el.ff;
ans = max(ans, vl + mx);
}
cout<<ans;
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
deal();
}
# | 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... |