Cod sursa(job #2773671)

Utilizator iustin.pericicaPericica Iustin iustin.pericica Data 8 septembrie 2021 12:04:56
Problema Loto Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <iostream>
#include <fstream>
#include <unordered_map>

using namespace std;

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

unordered_map <int, tuple <int, int, int>> hashMap;

int n, suma;
int numere[101];


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){

                int suma_locala = numere[i] + numere[j] + numere[l];
                if(suma_locala < suma) hashMap[suma_locala] = make_tuple(numere[i], numere[j], numere[l]);
                if(!(hashMap.find(suma - suma_locala) == hashMap.end())){
                      fout<<get<0>(hashMap[suma_locala]) << " "<<get<1>(hashMap[suma_locala]) << " "<<get<2>(hashMap[suma_locala])<<" ";
                      fout<<get<0>(hashMap[suma-suma_locala]) << " "<<get<1>(hashMap[suma-suma_locala]) << " "<<get<2>(hashMap[suma-suma_locala])<<" ";

                      return 0;
                }
    }



    fout<<-1;

    return 0;
}