Cod sursa(job #2661560)

Utilizator Alex_tz307Lorintz Alexandru Alex_tz307 Data 22 octombrie 2020 11:49:36
Problema Loto Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <bits/stdc++.h>

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

inline void max_self(int& a, int b) {
    a = max(a, b);
}

int N, S;
vector < int > a, sol(6);

void Back(int k) {
    for(int x : a) {
        sol[k] = x;
        if(k == 5) {
            int sum = 0;
            for(int i = 0; i < 6; ++i)
                sum += sol[i];
            if(sum == S) {
                for(int v : sol)
                    fout << v << ' ';
                exit(0);
            }
        }
        else {
            int sum = 0;
            for(int i = 0; i <= k; ++i)
                sum += sol[i];
            if(sum < S)
                Back(k + 1);
        }
            
    }
}

int main() {
    fin.sync_with_stdio(false);
    fout.sync_with_stdio(false);
    fin.tie(nullptr);
    fout.tie(nullptr);
    fin >> N >> S;
    a.resize(N);
    for(int& x : a) 
        fin >> x;
    sort(a.begin(), a.end(), greater<int>());
    if(*a.begin() * 6 < S) {
        fout << -1;
        return 0;
    }
    Back(0);
    fout << -1;
}