Cod sursa(job #3269489)

Utilizator jumaracosminJumara Cosmin-Mihai jumaracosmin Data 19 ianuarie 2025 13:03:07
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.47 kb
#include <bits/stdc++.h>

using namespace std;

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

const int SIZE = 105;

struct pereche
{
    int a, b, c;
};

int n, S;
int a[SIZE];
bool exista_sol = false;
unordered_map<int, pereche> M;
multiset<int> sol;

int main()
{
    fin >> n >> S;

    for(int i = 1; i <= n; ++i)
        fin >> a[i];

    //luam fiecare pereche de triplete (i, j, k)

    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            for(int k = 1; k <= n; ++k)
                M[a[i] + a[j] + a[k]] = {a[i], a[j], a[k]};

    //caut un raspuns

    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            for(int k = 1; k <= n; ++k)
            {
                int s = a[i] + a[j] + a[k];
                if(S >= s)
                    if(M.find(S - s) != M.end())
                    {
                        exista_sol = true;

                        auto it = M.find(S - s);
                        sol.insert(a[i]);
                        sol.insert(a[j]);
                        sol.insert(a[k]);
                        sol.insert(it->second.a);
                        sol.insert(it->second.b);
                        sol.insert(it->second.c);

                        for(auto e : sol)
                            fout << e << " ";

                        return 0;
                    }
            }

    if(!exista_sol)
        fout << -1;

    return 0;
}