Submission #1052632

#TimeUsernameProblemLanguageResultExecution timeMemory
1052632VMaksimoski008Sure Bet (CEOI17_sure)C++17
100 / 100
76 ms4432 KiB
#include <bits/stdc++.h> //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; signed main() { int n; cin >> n; vector<double> a(n), b(n), pref(n); for(int i=0; i<n; i++) cin >> a[i] >> b[i]; sort(a.rbegin(), a.rend()); sort(b.rbegin(), b.rend()); pref[0] = b[0]; for(int i=1; i<n; i++) pref[i] = pref[i-1] + b[i]; double ans = 0; double sum1 = 0; //sum1, i fixed //(sum1 - i - 2) - j //(sum2 - j) - (i - 2) double l=0, r=1e9; while(r - l > 1e-6) { double mid = (l + r) / 2; bool ok = 0; double sum1 = 0; for(int i=0; i<n&&!ok; i++) { sum1 += a[i]; if(sum1 - i - 2 < mid) continue; double tmp = (sum1 - i - 2) - mid; int mx = tmp; mx = min(mx, n-1); if(pref[mx] - mx - i - 2 >= mid && sum1 - i - 2 - mx >= mid) ok = 1; } if(ok) ans = l = mid; else r = mid; } cout << setprecision(4) << fixed << ans << '\n'; return 0; }

Compilation message (stderr)

sure.cpp: In function 'int main()':
sure.cpp:26:12: warning: unused variable 'sum1' [-Wunused-variable]
   26 |     double sum1 = 0;
      |            ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...