Cod sursa(job #2923602)

Utilizator alexpanaAlexandru Pana alexpana Data 16 septembrie 2022 15:12:54
Problema Dezastru Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;

int n, k;
std::vector<float> p;

int main() {
    ifstream fin("dezastru.in", ios::in);

    fin >> n >> k;

    for (int i = 0; i < n; ++i) {
        float v;
        fin >> v;
        p.push_back(v);
    }

    std::sort(p.begin(), p.end());

    float s = 0;
    int sc = 0;
    do {
        float r = 1;
        for (auto it = p.begin(); it < p.begin() + k; ++it) {
            r *= *it;
        }
        s += r;
        sc += 1;
    } while(std::next_permutation(p.begin(), p.end()));

    ofstream fout("dezastru.out", ios::out);
    fout << s / sc;
    fout.close();

    return 0;
}