This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimzize("Ofast,no-stack-protector")
#include<bits/stdc++.h>
#define int long long
#define quick ios::sync_with_stdio(0);cin.tie(0);
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define repd(x,a,b) for(int x=a;x>=b;x--)
#define lowbit(x) (x&-x)
#define sz(x) (int)(x.size())
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define mp make_pair
#define eb emplace_back
using namespace std;
typedef complex<int> P;
#define X real()
#define Y imag()
typedef pair<int,int> pii;
void debug(){
cout<<"\n";
}
template <class T,class ... U >
void debug(T a, U ... b){
cout<<a<<" ",debug(b...);
}
const int N=5e5+7;
const int INF=1e18;
pii p[N];
int a[N];
int pb[N];
int mx[N];
signed main(){
quick
int n;
cin>>n;
rep(i,1,n){
cin>>p[i].F>>p[i].S;
}
sort(p+1,p+n+1);
rep(i,1,n) a[i]=p[i].F,pb[i]=pb[i-1]+p[i].S;
mx[n+1]=-INF;
repd(i,n,1){
mx[i]=max(mx[i+1],pb[i]-a[i]);
}
int ans=0;
rep(i,1,n){
ans=max(ans,mx[i]+a[i]-pb[i-1]);
}
cout<<ans<<"\n";
return 0;
}
Compilation message (stderr)
art.cpp:1: warning: ignoring '#pragma GCC optimzize' [-Wunknown-pragmas]
1 | #pragma GCC optimzize("Ofast,no-stack-protector")
|
# | 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... |