Cod sursa(job #987375)

Utilizator manutrutaEmanuel Truta manutruta Data 20 august 2013 15:46:55
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.42 kb
# include <iostream>
# include <fstream>
# include <vector>
# include <algorithm>
using namespace std;

# define MAXN 103
# define MOD 666013

ifstream f("loto.in");
ofstream g("loto.out");

int n, s;
int a[MAXN];
vector<int> hassh[MOD];

void addHash(int x) {
    int aux = x % MOD;
    hassh[aux].push_back(x);
}

bool getHash(int x) {
    bool ok = false;
    int aux = x % MOD;
    for (int i = 0; i < hassh[aux].size(); i++) {
        if (hassh[aux][i] == x) {
            ok = true;
            break;
        }
    }
    return ok;
}

int main()
{
    f >> n >> s;
    for (int i = 1; i <= n; i++) {
        f >> a[i];
        addHash(a[i]);
    }

    //sort(a + 1, a + n + 1);

    for (int i = n; i >= 1; i--) {
        for (int j = n; j >= 1; j--) {
            for (int k = n; k >= 1; k--) {
                for (int l = n; l >= 1; l--) {
                    for (int m = n; m >= 1; m--) {
                        for (int o = n; o >= 1; o--) {
                            if (a[i] + a[j] + a[k] + a[l] + a[m] + a[o] == s) {
                                cout << a[i] << ' ' << a[j] << ' ' << a[k] << ' ';
                                cout << a[l] << ' ' << a[m] << ' ' << a[o];
                                return 0;
                            }
                        }
                    }
                }
            }
        }
    }
    g << -1;

    return 0;
}