Cod sursa(job #3309019)

Utilizator BogdanRazvanBogdan Razvan BogdanRazvan Data 30 august 2025 21:52:18
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <bits/stdc++.h>
 
using namespace std;
 
ifstream fin ("loto.in");
ofstream fout ("loto.out");

void usain_bolt()
{
    ios::sync_with_stdio(false);
    fin.tie(0);
}

void solve()
{
    int n, m;
    fin >> n >> m;
    vector<int> a(n);
    for (auto& val : a) {
        fin >> val;
    }
    queue<pair<int, int>> q;
    map<pair<int, int>, int> f;
    f[{0, 0}] = 1;
    q.push({0, 0});
    while (!q.empty()) {
        auto [sum, cnt] = q.front();
        q.pop();
        if (cnt == 6) {
            if (sum == m) {
                fout << "YES\n";
                return;
            } else {
                continue;
            }
        }
        for (auto val : a) {
            if (f.find({sum + val, cnt + 1}) == f.end()) {
                f[{sum + val, cnt + 1}] = 1;
                q.push({sum + val, cnt + 1});
            }
        }
    }
    fout << -1 << '\n';

    return;
}

int main()
{
    usain_bolt();
    
    int tt;
    
    tt = 1;
    while (tt--) {
        solve();
    }
    return 0;
}