Cod sursa(job #331134)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 12 iulie 2009 20:17:43
Problema Loto Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include<cstdio>
#define N 101
long long v[N],s;
short int n;
void citire()
{
	freopen("loto.in","r",stdin);
	freopen("loto.out","w",stdout);
	scanf("%hd%lld",&n,&s);
	for (int i=1; i<=n; ++i)
		scanf("%lld",&v[i]);
}
int caut(long long x)
{
	short int p=1,u=n,m;
	while (p!=u)
	{
		m=(p+u)/2;
		if (v[m]>=x)
			u=m;
		else
			p=m+1;
	}
	if (v[p]==x)
		return p;
	return -1;	
}
void tractor()
{
	for (int i1=1; i1<=n; ++i1)
		for (int i2=1; i2<=n; ++i2)
			for (int i3=1; i3<=n; ++i3)
				for (int i4=1; i4<=n; ++i4)
					for (int i5=1; i5<=n; ++i5)
					{
						long long x=s-(v[i1]+v[i3]+v[i2]+v[i4]+v[i5]); 
						int y=caut(x);
						if (y!=-1)
						{
							printf("%lld ",v[i1]);
							printf("%lld ",v[i2]);
							printf("%lld ",v[i3]);
							printf("%lld ",v[i4]);
							printf("%lld ",v[i5]);
							printf("%lld ",x);
							return;
						}
					}
	printf("-1");
}
int main()
{
	citire();
	tractor();
	return 0;
}