#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4") typedef long long LL; double d[100019]; const double EPS = 0.000000000001; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, t; cin>>n>>t; vector<double> v(n); for(auto &x : v)cin>>x; sort(v.begin(), v.end()); reverse(v.begin(), v.end()); int zero = 50005; d[zero] = 1; double res = 0; int p=zero; int k=zero; for(int i=0; i<n; i++){ double r = 0; int pp = k+1; for(int j=p; j<=k; j+=2){ double x = d[j] * v[i]; d[j-1] += d[j] - x; d[j+1] += x; d[j]=0; if(d[j-1] > EPS) pp = min(pp, j-1); } int kk=p-1; p=pp; k++; int start = zero+t; if(start%2 != p%2)start++; for(int j=p; j<=k; j+=2){ if(j>=start) r+=d[j]; if(d[j] > EPS) kk = max(kk, j); } k=kk; res = max(res, r); if(abs(1.0 - res) < EPS) break; } cout << fixed << setprecision(9) << res << "\n"; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #include <bits/stdc++.h> using namespace std; //#pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4") typedef long long LL; double d[100019]; const double EPS = 0.000000000001; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, t; cin>>n>>t; vector<double> v(n); for(auto &x : v)cin>>x; sort(v.begin(), v.end()); reverse(v.begin(), v.end()); int zero = 50005; d[zero] = 1; double res = 0; int p=zero; int k=zero; for(int i=0; i<n; i++){ double r = 0; int pp = k+1; for(int j=p; j<=k; j+=2){ double x = d[j] * v[i]; d[j-1] += d[j] - x; d[j+1] += x; d[j]=0; if(d[j-1] > EPS) pp = min(pp, j-1); } int kk=p-1; p=pp; k++; int start = zero+t; if(start%2 != p%2)start++; for(int j=p; j<=k; j+=2){ if(j>=start) r+=d[j]; if(d[j] > EPS) kk = max(kk, j); } k=kk; res = max(res, r); if(abs(1.0 - res) < EPS) break; } cout << fixed << setprecision(9) << res << "\n"; return 0; } |