Cod sursa(job #1553481)

Utilizator pulseOvidiu Giorgi pulse Data 19 decembrie 2015 22:27:31
Problema Loto Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <unordered_map>
#include <tuple>

using namespace std;

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

int N, S;
int a[105];
unordered_map<int, tuple<int, int, int> > m;

int main()
{
    fin >> N >> S;
    for (int i = 1; i <= N; ++i)
        fin >> a[i];

    for (int i = 1; i <= N; ++i)
    {
        for (int j = 1; j <= N; ++j)
        {
            for (int k = 1; k <= N; ++k)
            {
                m[a[i] + a[j] + a[k]] = make_tuple(a[i], a[j], a[k]);
            }
        }
    }

    for (int i = 1; i <= N; ++i)
    {
        for (int j = 1; j <= N; ++j)
        {
            for (int k = 1; k <= N; ++k)
            {
                auto it = m.find(S - a[i] - a[j] - a[k]);
                if (it != m.end())
                {
                    auto tup = it->second;
                    fout << a[i] << ' ' << a[j] << ' ' << a[k] << ' ' << get<0>(tup) << ' ' << get<1>(tup) << ' ' << get<2>(tup);
                    return 0;
                }
            }
        }
    }

    fout << -1;

    return 0;
}