Pagini recente » Cod sursa (job #1242718) | Cod sursa (job #2487958) | Cod sursa (job #1307387) | Cod sursa (job #2057798) | Cod sursa (job #987386)
Cod sursa(job #987386)
# 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");
struct punct{
int sum;
int a, b, c;
};
int n, s;
int a[MAXN];
vector<punct> hassh[MOD];
void addHash(punct x) {
int aux = x.sum % MOD;
hassh[aux].push_back(x);
}
bool existHash(int x) {
int aux = x % MOD;
for (int i = 0; i < hassh[aux].size(); i++) {
if (hassh[aux][i].sum == x) {
return true;
}
}
return false;
}
punct getHash(int x) {
int aux = x % MOD;
for (int i = 0; i < hassh[aux].size(); i++) {
if (hassh[aux][i].sum == x) {
return hassh[aux][i];
}
}
}
int main()
{
f >> n >> s;
for (int i = 1; i <= n; i++) {
f >> a[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
punct aux;
aux.sum = a[i] + a[j] + a[k];
aux.a = a[i];
aux.b = a[j];
aux.c = a[k];
addHash(aux);
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
int aux = s - a[i] - a[j] - a[k];
if (s > 0) {
if (existHash(aux) == true) {
punct x = getHash(aux);
g << a[i] << ' ' << a[j] << ' ' << a[k] << ' ';
g << x.a << ' ' << x.b << ' ' << x.c;
return 0;
}
}
}
}
}
g << -1;
return 0;
}