Submission #954457

#TimeUsernameProblemLanguageResultExecution timeMemory
954457koukirocksSure Bet (CEOI17_sure)C++17
0 / 100
0 ms344 KiB
#include <bits/stdc++.h> #define speed ios_base::sync_with_stdio(0); cin.tie(0) #define all(x) (x).begin(),(x).end() #define F first #define S second //#pragma GCC optimize("O3") //#pragma GCC target("avx,avx2") //#pragma GCC target("popcnt") namespace{using namespace std;} typedef long long ll; typedef double db; typedef long double ldb; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll MAX=1e5+10,P=1e9+7; const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f; const ldb eps=1e-6; int n; vector<ldb> a,b; vector<ldb> pa,pb; ldb w(int l,int r) { return min(pa[l],pb[r]); } int main() { speed; cin>>n; for (int i=1;i<=n;i++) { ldb x,y; cin>>x>>y; a.push_back(x); b.push_back(y); } auto cmp=[&](ldb a,ldb b) { return a>b; }; sort(all(a),cmp); sort(all(b),cmp); pa.resize(n+1); pb.resize(n+1); pa[0]=0; pb[0]=0; for (int i=1;i<=n;i++) { pa[i]=pa[i-1]+a[i-1]; pb[i]=pb[i-1]+b[i-1]; } ldb ans=0; for (int i=1;i<=2*n;i++) { // cout<<i<<" i\n"<<flush; int l=max(0,i-n),r=min(i,n); while (l<r) { int m1=(2*l+r)/3; int m2=(l+2*r+1)/3; // cout<<l<<" "<<m1<<" "<<m2<<" "<<r<<"\n"<<flush; if (w(m1,i-m1)<w(m2,i-m2)) l=m1+1; else r=m2-1; } // cout<<l<<" "<<i-l<<" "<<w(i,i-l)<<"\n"; ans=max(ans,w(l,i-l)-i); } cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...