Pagini recente » Cod sursa (job #2256341) | Cod sursa (job #2697855) | Cod sursa (job #657983) | Cod sursa (job #677682) | Cod sursa (job #692701)
Cod sursa(job #692701)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int main()
{
FILE *in = fopen("loto.in", "r");
freopen("loto.out", "w", stdout);
int n;
short a, b, c, d, e, f;
int S_C, NR[100];
bool stop = 0;
int S, vm = 0;
fscanf(in, "%d %d", &n, &S);
for(a=1;a<=n;++a)
{
fscanf(in, "%d", &NR[a]);
if(NR[a] > vm)
vm = NR[a];
}
fclose(stdin);
//sort(NR+1, NR+n+1);
if(6*vm < S)
cout<<"-1"<<"\n";
else
{
for(a=n;a>=1 && !stop;--a)
{
if(NR[a]+5*vm < S)
continue;
for(b=a;b>=1 && !stop;--b)
{
if(NR[a]+NR[b]+4*vm < S)
continue;
for(c=b;c>=1 && !stop;--c)
{
if(NR[a]+NR[b]+NR[c]+3*vm < S)
continue;
for(d=c;d>=1 && !stop;--d)
{
if(NR[a]+NR[b]+NR[c]+NR[d]+2*vm < S)
continue;
for(e=d;e>=1 && !stop;--e)
{
if(NR[a]+NR[b]+NR[c]+NR[d]+NR[e]+vm < S)
continue;
for(f=e;f>=1 && !stop;--f)
if(NR[a]+NR[b]+NR[c]+NR[d]+NR[e]+NR[f] == S)
{
cout<<NR[a]<<" "<<NR[b]<<" "<<NR[c]<<" "<<NR[d]<<" "<<NR[e]<<" "<<NR[f]<<"\n";
stop = 1;
break;
}
}
}
}
}
}
if(!stop)
cout<<"-1"<<"\n";
}
fclose(stdout);
return 0;
}