Cod sursa(job #2783571)

Utilizator Mendea_IanisMendea Ianis Teodor Mendea_Ianis Data 14 octombrie 2021 18:50:00
Problema Loto Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.08 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;
    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[i];
                c.second = V[k];
                d.first = V[j];
                d.second = c;
                H[V[i]+V[j]+V[k]] = d;
                a++;
            }
        }
    }
    for(auto it: H)
    {
        if(H.find(s - it.first) != H.end())
        {
            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;
            return 0;
        }
    }
    fout<<-1;

}