Cod sursa(job #1118696)

Utilizator alex_d01Alex Silviu alex_d01 Data 24 februarie 2014 12:46:08
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <cstdio>
int a[100], st[6], s, ss=0, n, m=0;

int solutie(int k)
{
	return (k==6);
}

int valid()
{
	return ss==s;
}

void tipar()
{
	for(int i=0; i<n; i++)
		printf("%d ", st[i]);
}

void lotto(int k)
{
	if(solutie(k) && valid())
	{
		m++;
	}
	else
	{
		if((k < 6) && (ss < s))
		{
			ss += a[k];
			st[k] = a[k];
			lotto(k+1);
		}
	}
	
}

void read(int &n, int &s)
{
	scanf("%d %d",&n, &s);
	for(int i=0; i<n; i++)
		scanf("%d",&a[i]);
}

int main()
{
	freopen("loto.in","r",stdin);
	freopen("loto.out","w",stdout);
	read(n,s);
	lotto(1);
	if(m > 1)
		tipar();
	else
		printf("-1");
	return 0;
}