Submission #1042761

#TimeUsernameProblemLanguageResultExecution timeMemory
1042761fryingducSure Bet (CEOI17_sure)C++17
100 / 100
55 ms4436 KiB
//#pragma GCC optimize("Ofast,unroll-loops") #include "bits/stdc++.h" using namespace std; #ifdef duc_debug #include "bits/debug.h" #else #define debug(...) #endif //#define int long long const int maxn = 1e5+5; int n; double a[maxn], b[maxn]; double ps[maxn]; int check(int mid, int argentina, double sum){ double left = min(sum - argentina + 1, ps[n] - ps[n - mid + 1] - argentina + 1); double right = min(sum - argentina - 1, ps[n] - ps[n - mid - 1] - argentina - 1); double cur = min(sum - argentina, ps[n] - ps[n - mid] - argentina); if(cur > left and cur > right) return 0; else{ if(cur < left) return 2; else return 1; } } void solve(){ cin >> n; for(int i = 1; i <= n; ++i){ cin >> a[i] >> b[i]; } sort(a + 1, a + n + 1); sort(b + 1, b + n + 1); ps[n + 1] = 0; for(int i = 1; i <= n; ++i){ ps[i] = ps[i - 1] + b[i]; } double ans = 0, sum = 0; for(int i = n; i; --i){ sum += a[i]; int l = 1, r = n; while(l <= r){ int mid = (l + r) / 2; int argentina = (n - i + 1) + mid; if(check(mid, argentina, sum) == 1){ l = mid + 1; } else if(check(mid, argentina, sum) == 2){ r = mid - 1; } else{ ans = max(ans, min(sum - argentina, ps[n] - ps[n - mid] - argentina)); break; } debug(i, mid, ans); } // ans = max(ans, rodi); } cout << fixed << setprecision(4) << ans; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int test = 1; // cin >> test; for(int i = 1; i <= test; i++){ // cout << "Case " << "#" << i << ": "; solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...