Cod sursa(job #14733)

Utilizator blasterzMircea Dima blasterz Data 9 februarie 2007 16:36:48
Problema Loto Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <cstdio>
#include <algorithm>
#include <hash_map.h>
#define maxn 128

using namespace std;

struct nod { int x, y,z;};

hash_map<int, nod, hash<int> >H;

int main()
{
	int x[maxn], n, S, i, j, k;
	
	freopen("loto.in", "r", stdin);
	scanf("%d %d\n", &n, &S);
	
	for(i=1;i<=n;i++) scanf("%d ", &x[i]);
	sort(x+1, x+n+1);
	nod t;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++) 
			for(k=1;k<=n;k++)
			{
				t.x=x[i];
				t.y=x[j];
				t.z=x[k];
				H[x[i]+x[j]+x[k]]=t;
			}
	
	int s;
	freopen("loto.out", "w", stdout);
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			for(k=1;k<=n;k++)
			{
				s=x[i]+x[j]+x[k];
				t=H[S-s];
				if(s+t.x+t.y+t.z==S) 
				{
				printf("%d %d %d %d %d %d\n", x[i], x[j], x[k], t.x, t.y, t.z);
					exit(0);
				}
			}
		printf("-1\n");
	return 0;
}