Submission #957367

#TimeUsernameProblemLanguageResultExecution timeMemory
957367_callmelucianSure Bet (CEOI17_sure)C++14
100 / 100
605 ms8440 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pl; typedef pair<int,int> pii; typedef tuple<int,int,int> tt; #define all(a) a.begin(), a.end() #define filter(a) a.erase(unique(all(a)), a.end()) const int mn = 1e5 + 5; const ld eps = 1e-9; const ld M = 1e9; ld a[mn], b[mn], pre_a[mn], pre_b[mn]; int n; bool ok (ld lb) { // check if there exist an answer >= lb for (int k = 0; k <= 2 * n; k++) { if (pre_a[min(n, k)] < lb + k) continue; int best = min(n, k); for (int b = min(n, k); b >= 1; b /= 2) { while (best - b >= 0 && pre_a[best - b] >= lb + k) best -= b; } if (pre_b[min(n, k - best)] >= lb + k) return 1; } return 0; } ld bs (ld L, ld R) { if (abs(L - R) < eps) return L; ld mid = (L + R) / 2.0; if (ok(mid + eps)) return bs(mid + eps, R); return bs(L, mid); } bool compare (ld a, ld b) { return a > b; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; sort(a + 1, a + 1 + n, compare); sort(b + 1, b + 1 + n, compare); for (int i = 1; i <= n; i++) { pre_a[i] = pre_a[i - 1] + a[i]; pre_b[i] = pre_b[i - 1] + b[i]; } cout << fixed << setprecision(4) << bs(0, M) << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...