Submission #877986

#TimeUsernameProblemLanguageResultExecution timeMemory
877986loncacbuoidaiSure Bet (CEOI17_sure)C++14
100 / 100
680 ms3924 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, k; double a[N], b[N]; bool check(double f) { // cerr << fixed << setprecision(10) << f << '\n'; int x = ([&] () -> int { int l = 1, r = n, ans = n * 3; while (l <= r) { int mid = (l + r) / 2; if ((double)a[mid] - k >= f) { ans = mid; r = mid - 1; } else l = mid + 1; } return ans; }()); int y = ([&] () -> int { int l = 1, r = n, ans = n * 3; while (l <= r) { int mid = (l + r) / 2; if ((double)b[mid] - k >= f) { ans = mid; r = mid - 1; } else l = mid + 1; } return ans; }()); // cerr << x << ' ' << y << " ok " << (x + y <= k) << '\n'; return x + y <= k; } int32_t main() { cin.tie(0)->sync_with_stdio(0); if (fopen("OXBET.inp", "r")) freopen("OXBET.inp", "r", stdin), freopen("OXBET.out", "w", stdout); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; sort(a + 1, a + n + 1, greater<double>()); sort(b + 1, b + n + 1, greater<double>()); for (int i = 1; i <= n; i++) a[i] += a[i - 1], b[i] += b[i - 1]; // for (int i = 1; i <= n; i++) // cerr << a[i] << ' ' << b[i] << '\n'; // k = 3; // check(0.5) << '\n'; // return 0; double res = 0; for (k = 1; k <= n * 2; k++) { // cerr << "k = " << k << '\n'; double l = 0, r = 2e8, ans = 0; for (int t = 1; t <= 50; t++) { double mid = (l + r) / 2; if (check(mid)) { ans = mid; l = mid; } else r = mid; } res = max(res, ans); } cout << fixed << setprecision(4) << res; return 0; }

Compilation message (stderr)

sure.cpp: In function 'int32_t main()':
sure.cpp:41:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   freopen("OXBET.inp", "r", stdin),
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:42:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   freopen("OXBET.out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...