Submission #1282194

#TimeUsernameProblemLanguageResultExecution timeMemory
1282194swishy123Sure Bet (CEOI17_sure)C++20
100 / 100
631 ms6716 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double using namespace std; const int def = 1e6+1; const int maxk = 18; const ll inf = 1e18; const ld eps = 1e-9; void solve(){ int n; cin >> n; vector<ld> a(n); auto b = a; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; sort(a.begin(), a.end(), greater<ld>()); sort(b.begin(), b.end(), greater<ld>()); vector<ld> prefa(n + 1, 0); auto prefb = prefa; for (int i = 1; i <= n; i++){ prefa[i] = prefa[i - 1] + a[i - 1]; prefb[i] = prefb[i - 1] + b[i - 1]; } ld res = 0; for (int i = 1; i <= 2 * n; i++){ ld l = 0, r = min(prefa[n], prefb[n]), mid = (l + r) / 2; while (r - l > eps){ int cnt1 = lower_bound(prefa.begin(), prefa.end(), mid) - prefa.begin(); int cnt2 = lower_bound(prefb.begin(), prefb.end(), mid) - prefb.begin(); if (cnt1 + cnt2 > i) r = mid; else l = mid; mid = (l + r) / 2; } res = max(res, l - i); } cout << setprecision(4) << fixed << res; } /* 0 0 0 0 0 */ main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (ifstream("input.txt").good()){ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } int t = 1; while (t--){ solve(); cout << "\n"; } }

Compilation message (stderr)

sure.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   55 | main(){
      | ^~~~
sure.cpp: In function 'int main()':
sure.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...