Cod sursa(job #2661557)

Utilizator Alex_tz307Lorintz Alexandru Alex_tz307 Data 22 octombrie 2020 11:44:35
Problema Loto Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 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
            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);
    int mx = 0;
    for(int& x : a) {
        fin >> x;
        max_self(mx, x);
    }
    if(mx * 6 < S) {
        fout << -1;
        return 0;
    }
    Back(0);
    fout << -1;
}