Submission #897700

#TimeUsernameProblemLanguageResultExecution timeMemory
897700LCJLYSure Bet (CEOI17_sure)C++14
60 / 100
2029 ms5104 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define show(x,y) cout << y << " " << #x << endl; #define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl; #define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl; #define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl; typedef pair<int,int>pii; typedef pair<pii,pii>pi2; void solve(){ int n; cin >> n; ld arr[n]; ld arr2[n]; for(int x=0;x<n;x++){ cin >> arr[x] >> arr2[x]; if(arr[x]<1.0) arr[x]=1.0; if(arr2[x]<1.0) arr2[x]=1.0; } sort(arr,arr+n,greater<ld>()); sort(arr2,arr2+n,greater<ld>()); ld prefix[n]; ld counter=0.0; for(int x=0;x<n;x++){ counter+=arr2[x]; prefix[x]=counter; } ld best=0.0; counter=0.0; for(int x=0;x<n;x++){ int l=0; int r=n-1; int mid; int cur=0; counter+=arr[x]; //show(counter,counter); while(l<=r){ mid=(l+r); ld hold=counter; //winning for arr ld win=prefix[mid]; //winning for arr2 if(hold>=win){ cur=mid; l=mid+1; } else r=mid-1; } //show(cur,cur); best=max(best,min(counter-(ld)(cur+x+2),prefix[cur]-(ld)(cur+x+2))); if(cur<n-1) cur++; best=max(best,min(counter-(ld)(cur+x+2),prefix[cur]-(ld)(cur+x+2))); //show(best,best); } cout << fixed << setprecision(4) << best; } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); //freopen("redistricting.in", "r", stdin); //freopen("redistricting.out", "w", stdout); int t=1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...