Cod sursa(job #65663)

Utilizator gigi_becaliGigi Becali gigi_becali Data 11 iunie 2007 12:55:03
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#define maxn 128
#define maxh 666777
	int x[maxn];
int N, S;
struct nod { int x, y, z;nod(){}; nod(int a, int b, int c){x=a; y=b;z=c;};};
vector<nod> H[maxn];

void insert(int x, int y, int z)
{
	int h=(x+y+z)%maxh;
	H[h].push_back(nod(x, y, z));
}

int main()
{
	freopen("loto.in", "r", stdin);
	freopen("loto.out", "w",stdout);
	scanf("%d %d\n", &N, &S);
	int i, j, k;

	for(i=1;i<=N;++i) scanf("%d ", x+i); 

	
	for(i=1;i<=N;++i)
		for(j=1;j<=N;++j)
			for(k=1;k<=N;++k)
				insert(x[i], x[j], x[k]);
			
	int s, h;
	nod *p;
	for(i=1;i<=N;++i)
		for(j=1;j<=N;++j)
			for(k=1;k<=N;++k)
			{
				s=S-(x[i]+x[j]+x[k]);
				h=s%maxh;
				vector<nod>::iterator p;
				for(p=H[s].begin();p!=H[s].end();++p)
					if(p->x+p->y+p->z==s)
					{
						int st[10], t=0;
						st[++t]=x[i];
						st[++t]=x[j];
						st[++t]=x[k];
						st[++t]=p->x;
						st[++t]=p->y;
						st[++t]=p->z;
						sort(st+1, st+t+1);
						for(int r=1;r<=t;++r) printf("%d ", st[r]);
						printf("\n");
						return 0;
					}
			}
		printf("-1\n");
		
	
	return 0;
}