제출 #678524

#제출 시각아이디문제언어결과실행 시간메모리
678524anhduc2701Art Exhibition (JOI18_art)C++17
0 / 100
0 ms212 KiB
/* #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimize("unroll-loops") */ #include<bits/stdc++.h> #define int long long #define all(x) x.begin(), x.end() #define len(x) ll(x.size()) #define eb emplace_back #define PI 3.14159265359 #define fi first #define se second #define mp make_pair #define pb push_back #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) #define BIT(x,i) (1&((x)>>(i))) #define MASK(x) (1LL<<(x)) #define task "tnc" using namespace std; typedef long long ll; const ll INF=5e18; const int maxn=1e6+5; const int mod=1e9+7; const int mo=998244353; using pi=pair<ll,ll>; using vi=vector<ll>; using pii=pair<pair<ll,ll>,ll>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n; pair<int,int> a[500005]; int pref[500005]; signed main() { cin.tie(0),cout.tie(0)->sync_with_stdio(0); //freopen(task".inp" , "r" , stdin); //freopen(task".out" , "w" , stdout); cin>>n; for(int i=1;i<=n;i++){ cin>>a[i].fi>>a[i].se; } sort(a+1,a+1+n); int ma0=-INF; int vt=0; int ma1=-INF; int vt1=0; for(int i=1;i<=n;i++){ pref[i]=pref[i-1]+a[i].se; if(a[i].fi-pref[i-1]>ma0){ ma0=a[i].fi-pref[i-1]; vt=i; } if(pref[i]-a[i].fi>=ma1){ ma1=pref[i]-a[i].fi; vt1=i; } } int ans=0; for(int i=vt+1;i<=n;i++){ ans=max(ans,pref[i]+ma0-a[i].fi); } for(int i=1;i<vt1;i++){ ans=max(ans,ma1-pref[i-1]+a[i].fi); } cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...