Cod sursa(job #2741326)

Utilizator blxqnAlina Voiculescu blxqn Data 15 aprilie 2021 21:02:44
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <iostream>
#include <fstream>
#include <unordered_map>

using namespace std;

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

struct sumTuple
{
    int x, y, z;
};

unordered_map<int, sumTuple> my_hash;

int numbers[102];

int main()
{
    int n, s, cnt = 0;
    fin>>n>>s;
    for (int i = 1; i <= n; i++)
        fin>>numbers[i];

    for (int i = 1; i <= n; i++)
        for (int j = i; j <= n; j++)
            for (int k = j; k <= n; k++)
                    my_hash[numbers[i] + numbers[j] + numbers[k]] = {numbers[i], numbers[j], numbers[k]};

    for(auto i : my_hash)
        if(my_hash.find(s - i.first) != my_hash.end())
        {
            fout<<my_hash[s - i.first].x<<" "<<my_hash[s - i.first].y<<" "<<my_hash[s - i.first].z<<" "<<i.second.x<<" "<<i.second.y<<" "<<i.second.z<<" ";
            cnt = 1;
            break;
        }
    if (cnt == 0)
        fout<<-1;
    return 0;
}