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
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;

const int N = 5e4+100;

ld p[N];
int n, t;

void solve() {
    cin>>n>>t;
    for (int i=1; i<=n; ++i) cin>>p[i];
    sort(p+1, p+n+1, greater<ld>());

    vector<vector<ld>> dp(n+1, vector<ld>(2*n+10, 0));

    dp[0][n] = 1;
    for (int i=1; i<=n; ++i) {
        for (int k=0; k<=2*n+3; ++k) {
            ld tmp = 0;
            if (k+1 <= 2*n+3) tmp += dp[i-1][k+1]*(1-p[i]);
            if (k-1 >= 0) tmp += dp[i-1][k-1]*p[i];
            dp[i][k] = tmp;
        }
    }

    ld ans = 0;
    for (int i=0; i<=n; ++i) {
        ld tmp = 0;
        for (int j=t+n; j<=2*n+3; ++j) tmp += dp[i][j];
        ans = max(ans, tmp);
    }

    cout<<setprecision(14)<<fixed;
    cout<<ans<<"\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t=1;
    while (t--) solve();
}