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

int ans_num, min_ans;
vector<float> probs;

float one_line_prob(const vector<float>& needed, int failed) {
    int toTake = needed.size() - failed;
    float total = 0;
    vector<bool> combination(needed.size(), false);
    fill(combination.begin(), combination.begin() + toTake, true);

    do {
        float product = 1;
        for (int i = 0; i < needed.size(); i++) {
            product *= (combination[i] ? needed[i] : (1 - needed[i]));
        }
        total += product;
    } while (prev_permutation(combination.begin(), combination.end()));

    return total;
}

float calculate_prob(const vector<float>& all_probs, int part) {
    vector<float> needed(all_probs.begin(), all_probs.begin() + part);
    int can_fail = (part - min_ans) / 2;
    float total_prob = 0;

    for (int p = 0; p <= can_fail; p++) {
        total_prob += one_line_prob(needed, p);
    }
    return total_prob;
}

int main() {
    cin >> ans_num >> min_ans;
    probs.resize(ans_num);

    for(int i = 0; i < ans_num; i++) {
        cin >> probs[i];
    }

    sort(probs.begin(), probs.end(), greater<float>());

    float max_prob = 0;
    for (int i = min_ans; i <= ans_num; i++) {
        max_prob = max(max_prob, calculate_prob(probs, i));
    }
    max_prob = round(max_prob * 1000000) / 1000000;

    cout << fixed << setprecision(20) << max_prob << endl;
    return 0;
}