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 "algorithm"
#include "vector"
#include "utility"
#include "iomanip"
#include "limits"
#include "numbers"

int main() {
    int t, n;
    std::cin >> n >> t;

    std::vector<long double> probs;

    for (int i = 0; i < n; i++) {
        long double p;
        std::cin >> p;
        probs.push_back(p);
    }
    std::sort(probs.begin(), probs.end());
    std::reverse(probs.begin(), probs.end());

    std::vector<long double> success_prob(n + 1, 0.0), temp(n + 1, 0.0);

    long double result = 0.0;
    success_prob[0] = 1.0;
    for (int attempted = 1; attempted <= n; attempted++) {
        long double p = probs[attempted - 1];
        temp[0] = success_prob[0] * (1 - p);
        for (int i = 1; i <= attempted; ++i) {
            temp[i] = p * success_prob[i - 1] + (1 - p) * success_prob[i];
        }
        for (int i = 0; i <= attempted; ++i) {
            success_prob[i] = temp[i];
        }

        long double winning_prob = 0.0;
        for (int successes = (t + attempted + 1) / 2; successes <= attempted; successes++) {
            winning_prob += success_prob[successes];
        }
        result = std::max(result, winning_prob);
    }

    std::cout << std::fixed;
    std::cout << std::setprecision(12);
    std::cout << result << std::endl;
    return 0;
}