Pagini recente » Cod sursa (job #484246) | Cod sursa (job #1658927) | Cod sursa (job #1917653) | Cod sursa (job #1792217) | Cod sursa (job #2839377)
#include <cstdio>
#include <unordered_map>
using namespace std;
struct sol
{
int x, y, z;
};
unordered_map <int, sol> m;
const int NMAX = 103;
int v[NMAX];
int main()
{
FILE *fin = fopen("loto.in", "r");
FILE *fout = fopen("loto.out", "w");
int n, s, i, j, k;
fscanf(fin, "%d %d", &n, &s);
for (i = 1; i <= n; i++)
fscanf(fin, "%d", &v[i]);
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
for (k = 1; k <= n; k++)
{
sol aux;
aux.x = v[i];
aux.y = v[j];
aux.z = v[k];
m[v[i] + v[j] + v[k]] = aux;
}
unordered_map <int, sol> :: iterator it, where;
for (it = m.begin(); it != m.end(); it++)
{/*
cout << it->first << " ";
cout << it->second.x << " " << it->second.y << " " << it->second.z << "\n";
*/
where = m.find(s - it->first);
if (where != m.end())
{
fprintf(fout, "%d %d %d %d %d %d",
(it->second).x, (it->second).y, (it->second).z,
where->second.x, where->second.y, where->second.z);
return 0;
}
}
fprintf(fout, "-1");
}