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
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>

int main() {
    int n, t;
    std::cin >> n >> t;
    
    std::vector<double> p(n);
    for (int i = 0; i < n; i++) {
        std::cin >> p[i];
    }
    
    // Sort probabilities in descending order
    std::sort(p.begin(), p.end(), std::greater<double>());
    
    double max_prob = 0.0;
    
    // Try answering k questions with highest probabilities
    for (int k = 0; k <= n; k++) {
        // We need to calculate the probability of getting at least t points
        // when answering the first k questions
        
        // dp[j] = probability of getting score j-k
        // We shift by k to handle negative scores
        std::vector<double> dp(2 * k + 1, 0.0);
        dp[k] = 1.0;  // Starting with score 0
        
        // Calculate probability distribution for answering k questions
        for (int i = 0; i < k; i++) {
            std::vector<double> new_dp(2 * k + 1, 0.0);
            for (int j = 0; j <= 2 * k; j++) {
                if (dp[j] > 0) {
                    // Correct answer: +1 point
                    if (j + 1 <= 2 * k) {
                        new_dp[j + 1] += dp[j] * p[i];
                    }
                    // Wrong answer: -1 point
                    if (j - 1 >= 0) {
                        new_dp[j - 1] += dp[j] * (1 - p[i]);
                    }
                }
            }
            dp = new_dp;
        }
        
        // Calculate probability of getting at least t points
        double prob = 0.0;
        for (int j = k + t; j <= 2 * k; j++) {
            prob += dp[j];
        }
        
        max_prob = std::max(max_prob, prob);
    }
    
    // Output the result with correct precision
    std::cout << std::fixed << std::setprecision(20) << max_prob << std::endl;
    
    return 0;
}