Cod sursa(job #997573)

Utilizator poptibiPop Tiberiu poptibi Data 14 septembrie 2013 15:47:56
Problema Loto Scor 65
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.56 kb
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;

const int NMAX = 110, MOD = 52919;

int N, S, V[NMAX];
vector<int> Hash[MOD];

void Insert(int Val)
{
    for(vector<int> :: iterator it = Hash[Val % MOD].begin(); it != Hash[Val % MOD].end(); ++ it)
        if(*it == Val)
            return ;
    Hash[Val % MOD].push_back(Val);
}

bool Is(int Val)
{
    for(vector<int> :: iterator it = Hash[Val % MOD].begin(); it != Hash[Val % MOD].end(); ++ it)
        if(*it == Val)
            return 1;
    return 0;
}

int main()
{
    freopen("loto.in", "r", stdin);
    freopen("loto.out", "w", stdout);

    scanf("%i %i", &N, &S);
    for(int i = 1; i <= N; ++ i) scanf("%i", &V[i]);

    for(int i = 1; i <= N; ++ i)
        for(int j = 1; j <= N; ++ j)
            for(int k = 1; k <= N; ++ k)
                Insert(V[i] + V[j] + V[k]);

    for(int i = 1; i <= N; ++ i)
        for(int j = 1; j <= N; ++ j)
            for(int k = 1; k <= N; ++ k)
                if(Is(S - V[i] - V[j] - V[k]))
                    for(int l = 1; l <= N; ++ l)
                        for(int m = 1; m <= N; ++ m)
                            for(int n = 1; n <= N; ++ n)
                                if(V[i] + V[j] + V[k] + V[l] + V[m] + V[n] == S)
                                {
                                    printf("%i %i %i %i %i %i\n", V[i], V[j], V[k], V[l], V[m], V[n]);
                                    return 0;
                                }

    printf("-1");

    return 0;
}