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
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, t;
    cin >> n >> t;
    vector<double> probs(n);
    for (int i = 0; i < n; i++){
        cin >> probs[i];
    }
    sort(probs.begin(), probs.end(), greater<double>());
    vector<double> dp(1, 1.0);
    int low = 0, high = 0;
    double mean = 0.0, var = 0.0;
 
    double best = 0.0;
    for(int m = 1; m <= n; m++){
        double p = probs[m - 1];
        double nmean = mean + p, nvar = var + p*(1.0 - p);
        double sigma = sqrt(nvar);
        int L_bound = 0;
        
        if(nmean - (6.0 * sigma) > 0) L_bound = (int) floor(nmean - 6.0*sigma);
        int R_bound = m;
        if(nmean + (6.0 * sigma) < m) R_bound = (int) ceil(nmean + 6.0*sigma);
 
        int newSize = R_bound - L_bound + 1;
        vector<double> newDP(newSize, 0.0);
 
        for(int k = L_bound; k <= R_bound; k++){
            double prob_val = 0.0;
            if(k >= low && k <= high) prob_val += dp[k - low] * (1.0 - p);
            if(k - 1 >= low && k - 1 <= high) prob_val += dp[(k - 1) - low] * p;
            newDP[k - L_bound] = prob_val;
        }
 
        dp = move(newDP);
        low = L_bound;
        high = R_bound;
        mean = nmean;
        var = nvar;
 
        if(m < t) continue;
 
        int req = (t + m + 1) / 2;
 
        double successProb = 0.0;
        int start = max(req, low);
        if(start <= high){
            for (int k = start; k <= high; k++){
                successProb += dp[k - low];
            }
        }
 
        best = max(best, successProb);
    }
 
    cout << fixed << setprecision(13) << best << "\n";
    return 0;
}