Cod sursa(job #14730)

Utilizator blasterzMircea Dima blasterz Data 9 februarie 2007 16:24:16
Problema Loto Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <cstdio>
#include <algorithm>
#define maxn 128

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