Cod sursa(job #2891213)

Utilizator EduardSanduSandu Eduard Alexandru EduardSandu Data 17 aprilie 2022 20:44:38
Problema Loto Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <bits/stdc++.h>
using namespace std;

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

struct threeTuple
{
    int first,second,third;
} disposal;

unordered_map<int, threeTuple> m1;

int v[105], n, s;

int main()
{
    fin>>n>>s;
    for(int i = 1; i<=n; i++)
        fin>>v[i];
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            for(int k=1; k<=n; k++)
            {
                m1[v[i] + v[j] + v[k]] = {v[i], v[j], v[k]};
            }
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            for(int k=1; k<=n; k++)
            {
                int decaut = s - (v[i] + v[j] + v[k]);
                if(m1.find(decaut) != m1.end())
                {
                    //am gasit solutie
                    fout<<v[i]<<' '<<v[j]<<' '<<v[k]<<' '<<m1[decaut].first<<' '<<m1[decaut].second<<' '<<m1[decaut].third<<' ';
                    return 0;
                }
            }
    fout<<-1;
    return 0;
}