Pagini recente » Cod sursa (job #813862) | Cod sursa (job #2455505) | Cod sursa (job #851998) | Cod sursa (job #577700) | Cod sursa (job #988284)
Cod sursa(job #988284)
# 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);
}
punct* existHash(int x) {
if (x <= 0) {
return false;
}
int aux = x % MOD;
for (int i = 0; i < hassh[aux].size(); i++) {
if (hassh[aux][i].sum == x) {
return &hassh[aux][i];
}
}
return NULL;
}
int main()
{
f >> n >> s;
for (int i = 1; i <= n; i++) {
f >> a[i];
}
//sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
punct aux, *b;
aux.sum = a[i] + a[j] + a[k];
aux.a = a[i];
aux.b = a[j];
aux.c = a[k];
if ((b = existHash(s - aux.sum)) != NULL) {
g << a[i] << ' ' << a[j] << ' ' << a[k] << ' ';
g << b->a << ' ' << b->b << ' ' << b->c;
return 0;
}
addHash(aux);
}
}
}
g << -1;
return 0;
}