Cod sursa(job #151304)

Utilizator zobicaMarin Marin zobica Data 7 martie 2008 23:29:16
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.32 kb
#include<fstream>  

using namespace std;  

long a[100],T;  
ofstream fout("loto.out");  

short n;  

void citire(){  
	ifstream fin("loto.in");  
	fin>>n>>T;  
	for (short i=0;i<n;i++)  
		fin>>a[i];  
	fin.close();  
}  

void bule(){  
	short ok=0,p=n;  
	while(ok==0){  
		ok=1;  
		p--;  
		for (short i=0;i<p;i++)  
			if (a[i] < a[i+1]){  
				long aux=a[i];  
				a[i]=a[i+1];  
				a[i+1]=aux;  
				ok=0;}  
	}  
}  
int parc(){  
	for (short i = 0; i < n; i++) {  
		long s = a[i];  
		if (s > T)  
			continue;  
		for (short j = i; j < n; j++) {  
			long s1 = s + a[j];  
			if (s1 > T)  
				continue;  
			for (short k = j; k < n; k++) {  
				long s2 = s + a[k];  
				if (s2 > T)  
					continue;  
				for (short l = k; l < n; l++) {  
					long s3 = s + a[l];  
					if (s3 > T)  
						continue;  
					for (short o = l; o < n; o++) {  
						long x = T - s3 - a[o];  
						if (x >= 0 && x <=a[o])  
							for (short p = o ; p < n; p++)  
								if ( x == a[p]){  
									fout<<a[i]<<" "<<a[j]<<" "<<a[k]<<" "<<a[l]<<" "<<a[o]<<" "<<x<<"\n";  
									return 1;  
								}  
					}  
				}  
			}  
		}  

	}  
	return 0;  
}  

int main(){  
	citire();  
	bule();    
	if (a[n-1] > T || !parc())  
		fout<<"-1";  
	fout.close();  
	return 0;  
}