Cod sursa(job #2783550)

Utilizator Mendea_IanisMendea Ianis Teodor Mendea_Ianis Data 14 octombrie 2021 18:18:11
Problema Loto Scor 75
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 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;
            fout<<H[s - it.first].first<<' '<<H[s - it.first].second.first<<' '<<H[s - it.first].second.second<<' ';
            fout<<it.second.first<<' '<<it.second.second.first<<' '<<it.second.second.second;
            break;
        }
    }
    if(ok == 0)
        fout<<-1;

}