Cod sursa(job #575714)

Utilizator GaborGabrielFMI - GabrielG GaborGabriel Data 8 aprilie 2011 17:51:13
Problema Loto Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream.h>
#include <algorithm>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
int n,s,v[101];
int i,j,k,l,m,x;

int main()
{	
	f>>n>>s;
	for(i=1;i<=n;i++)
		f>>v[i];
	sort(v+1,v+n+1);
	for(i=1;i<=n;i++)
		for(j=n;j>=1;j--)
			for(k=1;k<=n;k++)
				for(l=n;l>=1;l--)
					for(m=1;m<=n;m++)
						for(x=n;x>=1;x--)
							if(v[i]+v[j]+v[k]+v[l]+v[m]+v[x] == s)
							{
								g<<v[i]<<' '<<v[j]<<' '<<v[k]<<' '<<v[l]<<' '<<v[m]<<' '<<v[x]<<'\n';
								return 0;
							}
	g<<"-1"<<'\n';
	f.close();
	g.close();
	return 0;
}