Cod sursa(job #2748283)

Utilizator faalaviaFlavia Podariu faalavia Data 30 aprilie 2021 00:27:20
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <unordered_map>

using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
struct triplet
{
    int a, b, c;
};

int v[102];
unordered_map<int, triplet> hashh;

int n,suma, i, j, k, nr;
long long s;
int main()
{

    fin >> n >> s;
    for(i = 1; i <= n; ++i)
        fin >> v[i];

    for(i = 1; i <= n; ++i)
    {
        for(j = i; j <= n; ++j)
        {
            for(k = j; k <= n; ++k)
            {
                nr = v[i] + v[j] + v[k];
                triplet sumof3;
                sumof3.a = v[i];
                sumof3.b = v[j];
                sumof3.c = v[k];
                hashh[nr] = sumof3;

            }
        }
    }
    for(i = 1; i <= n; ++i)
        for(j = i; j <= n; ++j)
            for(k = j; k <= n; ++k)
            {
                suma=v[i]+v[j]+v[k];
                if(hashh.count(s-suma))
                {
                    fout<<v[i]<<" "<<v[j]<<" "<<v[k]<<" "<<v[hashh[s-suma].a]<<" "<<v[hashh[s-suma].b]<<" "<<v[hashh[s-suma].c];
                    return 0;
                }
            }
    fout <<-1;

    return 0;
}