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 ll long long
#define fi first
#define se second
#define sst string
#define pb push_back
#define maxco 100000+5
#define lld long double
#define cha ios_base::sync_with_stdio(false);
#define ffl cout.flush();
#define phi acos(-1)
#define mod 707
#define mr make_pair
#define pqin priority_queue<ll,vector<ll>,greater<>>
#define pqpair priority_queue<pair<ll,ll> ,vector<pair<ll,ll>>,greater<pair<ll,ll>>>
#define pqpair2 priority_queue<pair<pair<ll,ll>,pair<ll,ll>>,vector<pair<pi,pair<ll,ll>>>,greater<pair<pi,pair<ll,ll>>>>
#define INF 1000000009
#define MAXN 500069
#define pi pair<ll,ll>
ll mvx[]={1,-1,0,0};
ll mvy[]={0,0,1,-1};
pair<ll,ll> pr[MAXN];
ll ps[MAXN];
int main(){
ll n;
cin>>n;
set<ll> st;
for(ll i=1;i<=n;i++){
cin>>pr[i].fi>>pr[i].se;
}
sort(pr+1,pr+n+1);
ll mk=0;
ll idx;
for(ll i=1;i<=n;i++){
ps[i]+=ps[i-1]+pr[i].se;
if(ps[i]-pr[i].fi>mk){
mk=ps[i]-pr[i].fi;
idx=i;
}
}
ll ans=0;
for(ll i=1;i<=idx;i++){
ans=max(ans,pr[i].fi+ps[idx]-ps[i-1]-pr[idx].fi);
}
for(ll i=1;i<=n;i++){
ans=max(ans,pr[i].se-pr[i].fi);
}
cout<<ans<<endl;
}
Compilation message (stderr)
watching.cpp: In function 'int main()':
watching.cpp:44:17: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
44 | for(ll i=1;i<=idx;i++){
| ~^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |