Cod sursa(job #2809443)

Utilizator DordeDorde Matei Dorde Data 27 noiembrie 2021 00:18:59
Problema Loto Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
int const N = 101;
int v[N] , n , s , best , st[7];
void bkt(int k , int sum){
    if (k == 7 && sum == s){
        for(int i = 1 ; i <= 6 ; ++ i)
            fout << v [st [i]] << ' ';
        fout << '\n';
        exit (0);
    }
    for(int i = st[k - 1]; i <= n ; ++ i){
        if (sum + (7 - k) * best < s)
            continue;
        st[k] = i;
        bkt(k + 1 , sum + v[i]);
        st[k] = 0;
    }
}
int main()
{
    fin >> n >> s;
    for(int i = 1 ; i <= n ; ++ i){
        fin >> v [i];
        best = max(best , v[i]);
    }
    sort(v , v + n);
    st[0] = 1;
    bkt(1 , 0);
    fout << "-1\n";
    fin.close();
    fout.close();
    return 0;
}