Cod sursa(job #412193)

Utilizator BalcauIonutFMI-Balcau Ionut BalcauIonut Data 5 martie 2010 13:42:51
Problema Loto Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include<fstream>
#include<algorithm>
using namespace std;
int main(){
	int s,a[110],st[10];
	short i,j,k,l,h,m,n;
	ifstream f("loto.in");
	ofstream g("loto.out");
	f>>n>>s;
	for(i=1;i<=n;++i)
		f>>a[i];
	sort(a+1,a+n+1);
	for(i=n;i>0;--i){
		//st[1]=a[i];
		for(j=n;j>0;--j){
			//st[2]=st[1]+a[j];
			for(k=n;k>0;--k){
				//st[3]=st[2]+a[k];
				for(l=n;l>0;--l){
					//st[4]=st[3]+a[l];
					for(h=n;h>0;--h){
						//st[5]=st[4]+a[h];
						for(m=n;m>0;--m){
							//st[6]=st[5]+a[m];
							if(a[i]+a[j]+a[k]+a[l]+a[h]+a[m]==s){
								g<<a[i]<<' '<<a[j]<<' '<<a[k]<<' '<<a[l]<<' '<<a[h]<<' '<<a[m];
								return 0;
							}
						}
					}
				}
			}
		}
	}
	g<<-s;
	return 0;
}