Pagini recente » Cod sursa (job #2418964) | Cod sursa (job #1551071) | Cod sursa (job #956720) | Diferente pentru teorema-chineza-a-resturilor intre reviziile 85 si 84 | Cod sursa (job #686966)
Cod sursa(job #686966)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int a, b, c, d, e, f;
long S_C, NR[101];
int main()
{
freopen("loto.in", "r", stdin);
freopen("loto.out", "w", stdout);
int n;
bool stop = 0;
long S;
cin>>n>>S;
for(a=1;a<=n;++a)
cin>>NR[a];
fclose(stdin);
sort(NR+1, NR+n+1);
if(NR[n] * 6 < S)
cout<<"-1"<<"\n";
else
{
for(a=n;a>=1 && !stop;--a)
for(b=a;b>=1 && !stop;--b)
for(c=b;c>=1 && !stop;--c)
for(d=c;d>=1 && !stop;--d)
{
if(NR[a]+NR[b]+NR[c]+NR[d]+2*NR[n] < S)
{
cout<<"-1\n";
stop = 1;
break;
}
for(e=d;e>=1 && !stop;--e)
{
if(NR[a]+NR[b]+NR[c]+NR[d]+NR[e]+NR[n] < S)
{
cout<<"-1\n";
stop = 1;
break;
}
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;
}