IanisBelu

USACO 2019 February, Platinum, Cow Dating

Nov 13th, 2025
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int NMAX = 1e6+5;
  6.  
  7. int n;
  8. double a[NMAX];
  9.  
  10. void read() {
  11.    cin >> n;
  12.    for (int i = 1, x; i <= n; i++) {
  13.       cin >> x;
  14.       a[i] = double(x) / 1e6;
  15.    }
  16. }
  17.  
  18. int solve() {
  19.    double ans = 0, sum = 0, prod = 1;
  20.    
  21.    for (int l = 1, r = 1; l <= n; l++) {
  22.       while (r <= n && sum * prod < (sum + (a[r] / (1.0 - a[r]))) * prod * (1.0 - a[r])) {
  23.          sum += a[r] / (1.0 - a[r]);
  24.          prod *= 1.0 - a[r];
  25.          r++;
  26.       }
  27.       ans = max(ans, sum * prod);
  28.       sum -= a[l] / (1.0 - a[l]);
  29.       prod /= 1.0 - a[l];
  30.    }
  31.  
  32.    return ans * 1e6;
  33. }
  34.  
  35. signed main() {
  36. #ifdef LOCAL
  37.    freopen("input.txt", "r", stdin);
  38. #else
  39.    freopen("cowdate.in", "r", stdin);
  40.    freopen("cowdate.out", "w", stdout);
  41. #endif
  42.  
  43.    ios_base::sync_with_stdio(false);
  44.    cin.tie(0);
  45.    cout.tie(0);
  46.  
  47.    read();
  48.    cout << solve();
  49.  
  50.    return 0;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment