Cod sursa(job #2773667)

Utilizator iustin.pericicaPericica Iustin iustin.pericica Data 8 septembrie 2021 11:53:11
Problema Loto Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <iostream>
#include <fstream>
#include <unordered_set>

using namespace std;

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

unordered_set <int> hashMap;

int n, suma;
int numere[101];

void afisareSuma(int suma){

    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
            for(int l = 1;l<=n;++l){
                if(numere[i] + numere[j] + numere[l] == suma){
                    fout << numere[i] << " " << numere[j] << " " << numere[l]<<" ";
                    return;
                }
        }

}

int main()
{

    fin>>n>>suma;

    for(int i = 1;i<=n;++i){
        fin>>numere[i];
    }


    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
            for(int l = 1;l<=n;++l){
                hashMap.insert(numere[i] + numere[j] + numere[l]);
    }


    for (const auto& elem: hashMap) {


        if(!(hashMap.find(suma - elem) == hashMap.end())){
              afisareSuma(elem);
              afisareSuma(suma - elem);
              return 0;
        }
    }



    fout<<-1;

    return 0;
}