Cod sursa(job #3279644)

Utilizator 9onelostSendrescu Tudor-Gabriel 9onelost Data 23 februarie 2025 18:17:22
Problema Loto Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <bits/stdc++.h>
using namespace std;

ifstream fin("loto.in");
ofstream fout("loto.out");

const int MAX_N = 100;

int n, s;

int v[MAX_N], sol[6];

bool gasit = false;

void bkt(int poz, int sum) {

    if (gasit) return;

    if (poz == 6) {

        if (sum == s) {

            gasit = true;

        }

        return;

    }

    for (int i = 0; i < n; i++) {

        if (sum + v[i] > s) continue;

        sol[poz] = v[i];

        bkt(poz + 1, sum + v[i]);

        if (gasit) return;

    }

}

int main() {

    fin >> n >> s;

    for (int i = 0; i < n; i++) {

        fin >> v[i];

    }

    sort(v, v + n, greater<int>());

    bkt(0, 0);

    if (gasit) {

        for (int i = 0; i < 6; i++) {

            fout << sol[i] << " ";

        }

    } else {

        fout << "-1";

    }

    return 0;
}