Cod sursa(job #2891214)

Utilizator EduardSanduSandu Eduard Alexandru EduardSandu Data 17 aprilie 2022 20:48:46
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 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;

void firstgen()
{
    for(int i=1; i<=n; i++)
        for(int j=i; j<=n; j++)
            for(int k=j; k<=n; k++)
            {
                int suma = v[i] + v[j] + v[k];
                m1[suma] = {v[i], v[j], v[k]};
            }
}

bool searchgen()
{
    unordered_map<int, threeTuple>::iterator caut;

    for(auto& it: m1)
    {
        int suma = it.first;
        caut = m1.find(s-suma);
        if(caut != m1.end())
        {
            //am gasit solutie
            fout<<it.second.first<<' '<<it.second.second<<' '<<it.second.third<<' '<<caut->second.first<<' '<<caut->second.second<<' '<<caut->second.third<<' ';
            return 1;
        }
    }
    return 0;
}

int main()
{
    fin>>n>>s;
    for(int i = 1;i<=n;i++)
        fin>>v[i];
    firstgen();
    if(!searchgen())
        fout<<-1;
    return 0;
}