Cod sursa(job #1426548)

Utilizator greenadexIulia Harasim greenadex Data 29 aprilie 2015 21:32:48
Problema Loto Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <fstream>
#include <unordered_map>
#include <vector>

using namespace std;

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

unordered_map <int, int> sums;
vector <int> numbers;

int N, S;

int main()
{
    fin >> N >> S;
    for (int i = 1, nr; i <= N; i++){
        fin >> nr;
        numbers.push_back(nr);
    }
    for (auto x : numbers)
        for (auto y : numbers)
            for (auto z : numbers){
                int sum = x + y + z;
                if (sum <= S)
                    sums[sum] = 1;
            }

    for (auto x : numbers)
        for (auto y : numbers)
            for (auto z : numbers){
                int sum = x + y + z;
                if (sums.count(sum) && sums.count(S - sum)){
                    for (auto a : numbers)
                    for (auto b : numbers)
                    for (auto c : numbers)
                    if (a + b + c == S - sum){
                        fout << x << ' ' << y << ' ' << z << ' '
                             << a << ' ' << b << ' ' << c;
                        return 0;
                    }
                }
            }
    fout << -1;
    return 0;
}