# Cod sursa(job #1165202)

Utilizator Data 2 aprilie 2014 15:54:59 Loto 65 cpp done Arhiva de probleme 1.67 kb
``````#include <algorithm>
#include <fstream>
#include <vector>
using namespace std;
const int MAX_N = 105;
const int HMOD = 66013;

int a[MAX_N];
vector<int> table[HMOD];

inline bool look_for(int x) {
int h = x % HMOD;
for(int i = 0; i < static_cast<int>(table[h].size()); ++ i) {
if(table[h][i] == x) {
return true;
}
}
return false;
}

inline void insert(int x) {
if(!look_for(x)) {
table[x % HMOD].push_back(x);
}
}

int main() {
ifstream fin("loto.in");
ofstream fout("loto.out");
int n, s;
fin >> n >> s;
for(int i = 1; i <= n; ++ i) {
fin >> a[i];
}
for(int i = 1; i <= n; ++ i) {
for(int j = i; j <= n; ++ j) {
for(int k = j; k <= n; ++ k) {
insert(a[i] + a[j] + a[k]);
}
}
}
for(int i = 1; i <= n; ++ i) {
for(int j = i; j <= n; ++ j) {
for(int k = j; k <= n; ++ k) {
if(look_for(s - a[i] - a[j] - a[k])) {
for(int i2 = 1; i2 <= n; ++ i2) {
for(int j2 = i2; j2 <= n; ++ j2) {
for(int k2 = j2; k2 <= n; ++ k2) {
if(a[i] + a[j] + a[k] + a[i2] + a[j2] + a[k2] == s) {
fout << a[i] << " " << a[j] << " " << a[k] << " " << a[i2] << " " << a[j2] << " " << a[k2] << "\n";
return 0;
}
}
}
}
}
}
}
}
fout << "-1\n";
return 0;
}
``````