Cod sursa(job #3240865)

Utilizator Manolea_Teodor_StefanManolea Teodor Stefan Manolea_Teodor_Stefan Data 22 august 2024 10:10:46
Problema Loto Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <bits/stdc++.h>
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

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

int n,s;

bool ok;
vector<int> stk;
vector<int> v;
void solve (const int numberLeft = 6, const int sumLeft = s) {
    if (numberLeft == 0) {
        if (sumLeft == 0)
            ok = true;
        return;
    }
    for (const auto i : v) {
        if (sumLeft - i >= 0) {
            stk.push_back(i);
            solve(numberLeft - 1, sumLeft - i);
            if (ok)
                return;
            stk.pop_back();
        }

    }
}

int main() {
    fin >> n >> s;
    v.resize(n);
    sort(v.begin(),v.end(),greater<int>());
    for (auto& i : v)
        fin >> i;
    solve();
    if (ok) {
        for (const int i : stk)
            fout << i << ' ';
    } else {
        fout << -1;
    }
    return 0;
}