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
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

struct Question {
    double probability;
    int index;
};

bool compare(Question a, Question b) {
    return a.probability > b.probability;
}

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

    std::vector<Question> questions(n);
    for (int i = 0; i < n; i++) {
        std::cin >> questions[i].probability;
        questions[i].index = i;
    }

    std::sort(questions.begin(), questions.end(), compare);

    double maxProbability = 0.0;

    std::vector<double> totalQuestions(n + 1, 0.0);

    for (int good_answers = t; good_answers <= n; good_answers++) {
        for (int bad_answers = 0; bad_answers + good_answers <= n; bad_answers++) {
            int total = good_answers + bad_answers;
            if (total > n || good_answers - bad_answers < t) {
                break;
            }

            std::vector<double> selected_probs;
            for (int i = 0; i < total; i++) {
                selected_probs.push_back(questions[i].probability);
            }

            std::cout << "Selected questions: " << std::endl;
            std::cout << "good_answers: " << good_answers << " bad_answers: " << bad_answers << std::endl;
            for (int i = 0; i < total; i++) {
                std::cout << questions[i].index << " " << questions[i].probability << " " << std::endl;
            }
            double probability = 1.0;
            for (int i = 0; i < good_answers; i++) {
                probability *= selected_probs[i]; // Dobra odpowiedź
            }
            for (int i = good_answers; i < total; i++) {
                probability *= (1.0 - selected_probs[i]); // Zła odpowiedź
            }
            std::cout << "Probability: " << probability << std::endl;

            totalQuestions[total] += probability;

            double currProbability = totalQuestions[total];

            maxProbability = std::max(maxProbability, currProbability);
        }
    }

    std::cout << "Total questions: " << std::endl;
    for (int i = 0; i <= n; i++) {
        std::cout << i << " " << totalQuestions[i] << std::endl;
    }
    std::cout << std::fixed << std::setprecision(7) << maxProbability << std::endl;

    return 0;
}