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

// #define double long double

double p[50007];
double dp[2][1000007];

int n, t;

bool f(double x, double y) {
    return x > y;
}

static inline int id(int i) {
    return i + n + 1;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> t;

    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    sort(p, p + n, f);

    // for (int i = 0; i < n; i++) {
    //     cout << p[i] << " ";
    // }

    double* last = dp[0];
    double* curr = dp[1];

    last[id(1)] = p[0];
    last[id(-1)] = (double)(1) - p[0];

    double wyn = t == 1 ? p[0] : 0.0;

    for (int i = 1; i < n; i++) {
        double s = 0.0;
        for (int w = -(i + 1); w <= i + 1; w++) {
            curr[id(w)] = last[id(w - 1)] * p[i] + last[id(w + 1)] * ((double)(1) - p[i]);
            if (w >= t) s += curr[id(w)];
        }
        wyn = max(wyn, s);
        swap(last, curr);

        // for (int w = -1; w <= i; w++) {
        //     curr[id(i)] = (double)(0);
        // }
    }

    cout << setprecision(7) << fixed << wyn << "\n";
}