Cod sursa(job #2783555)

Utilizator ionanghelinaIonut Anghelina ionanghelina Data 14 octombrie 2021 18:21:49
Problema Loto Scor 75
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <iostream>
#include <unordered_map>
#include <fstream>

using namespace std;

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

pair <int , int> c;
pair <int, pair<int,int> > d;

unordered_map <int , pair<int , pair<int,int> > > H;

int main()
{
    long long n,s,V[100],a = 1,ok = 0;
    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)
            {
                c.first = V[j];
                c.second = V[k];
                d.first = V[i];
                d.second = c;
                H[V[i]+V[j]+V[k]] = d;
                a++;
            }
        }
    }
    for(auto it: H)
    {
        if(H.find(s - it.first) != H.end())
        {
            ok = 1;
            pair<int,pair<int,int> > pr = H[s-it.first];
            fout<<pr.first<<' '<<pr.second.first<<' '<<pr.second.second<<' ';
            fout<<it.second.first<<' '<<it.second.second.first<<' '<<it.second.second.second;
            return 0;
        }
    }
    if(ok == 0)
        fout<<-1;

}