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
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long double ld;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, t;
    cin >> n >> t;
    vector<ld> p(n);
    for (int i = 0; i < n; i++){
        cin >> p[i];
    }
    sort(p.begin(), p.end(), greater<ld>());
    
    vector<ld> dp(1, 1.0);
    ld best = 0.0;
    
    for (int m = 0; m < n; m++){
        int current = m + 1;
        vector<ld> new_dp(current + 1, 0.0);
        ld prob = p[m];
        for (int r = current - 1; r >= 0; r--){
            new_dp[r + 1] += dp[r] * prob;
            new_dp[r]   += dp[r] * (1.0 - prob);
        }
        dp = move(new_dp);
        
        if(current < t){
            continue;
        }
        int req = (current + t + 1) / 2;
        ld passProb = 0.0;
        for (int r = req; r <= current; r++){
            passProb += dp[r];
        }
        best = max(best, passProb);
    }
    
    cout << fixed << setprecision(7) << best << "\n";
    return 0;
}