Cod sursa(job #3128594)

Utilizator florinilie324Ilie Florin Alexandru florinilie324 Data 10 mai 2023 08:09:53
Problema Loto Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.38 kb
#include <iostream>
#include <fstream>
#include <unordered_set>
#include <vector>
#include <algorithm>

using namespace std;

bool gaseste_combinatie(int N, int S, vector<int> &numere, vector<int> &combinatie) {
    for (int a = 0; a < N; ++a) {
        for (int b = 0; b < N; ++b) {
            for (int c = 0; c < N; ++c) {
                for (int d = 0; d < N; ++d) {
                    for (int e = 0; e < N; ++e) {
                        for (int f = 0; f < N; ++f) {
                            if (numere[a] + numere[b] + numere[c] + numere[d] + numere[e] + numere[f] == S) {
                                combinatie = {numere[a], numere[b], numere[c], numere[d], numere[e], numere[f]};
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}

int main() {
    int N, S;
    ifstream fin("loto.in");
    ofstream fout("loto.out");

    fin >> N >> S;
    vector<int> numere(N);
    for (int i = 0; i < N; ++i) {
        fin >> numere[i];
    }

    vector<int> combinatie;
    if (gaseste_combinatie(N, S, numere, combinatie)) {
        for (int i = 0; i < 6; ++i) {
            fout << combinatie[i] << ' ';
        }
    } else {
        fout << -1;
    }

    fin.close();
    fout.close();
    return 0;
}