Submission #185318

#TimeUsernameProblemLanguageResultExecution timeMemory
185318AlexPop28Sure Bet (CEOI17_sure)C++11
100 / 100
133 ms4596 KiB
#include <bits/stdc++.h> #define dbg() cerr << #define name(x) (#x) << ": " << (x) << ' ' << using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<double> a(n), b(n); for (int i = 0; i < n; ++i) { cin >> a[i] >> b[i]; a[i] -= 1.0; b[i] -= 1.0; } sort(a.rbegin(), a.rend()); sort(b.rbegin(), b.rend()); vector<double> sum(n); for (int i = 0; i < n; ++i) { sum[i] = b[i]; if (i != 0) sum[i] += sum[i - 1]; } double ans = 0.0, sum_a = 0.0; for (int cnt_a = 1; cnt_a <= n; ++cnt_a) { auto Compute = [&](int cnt_b) { return min(sum_a - cnt_b, sum[cnt_b - 1] - cnt_a); }; sum_a += a[cnt_a - 1]; int lo = 1, hi = n, res = 0; while (lo <= hi) { int one = lo + (hi - lo) / 3; int two = hi - (hi - lo) / 3; if (Compute(one) <= Compute(two)) { res = two; lo = one + 1; } else { res = one; hi = two - 1; } } // dbg() name(cnt_a) name(res) name(sum_a) name(sum[res - 1]) name(Compute(res)) endl; ans = max(ans, Compute(res)); } cout << fixed << setprecision(4) << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...