Pagini recente » Cod sursa (job #496465) | Cod sursa (job #170189) | Cod sursa (job #508941) | Cod sursa (job #2413091) | Cod sursa (job #361548)
Cod sursa(job #361548)
# include <fstream>
using namespace std;
long long int n, s, v[105], x[10], sum, pp;
ofstream fout ("loto.out");
void citire ()
{
int i;
ifstream fin ("loto.in");
fin>>n>>s;
for (i=1;i<=n;i++)
fin>>v[i];
}
void afis ()
{
int i;
for (i=1;i<=6;i++)
fout<<x[i]<<" ";
}
void bk (int k)
{
int i;
for (i=1;i<=n && k<=6 && pp==0;i++)
{
x[k]=v[i];
sum += v[i];
if (sum<=s)
{
if (sum==s && k==6)
afis (), pp=1;
else
if (k<6 && sum<s)
bk(k+1);
}
sum-=v[i];
}
}
void sort ()
{
int i, gata, cpt, capat;
long long aux;
gata=0;
capat=n;
while (!gata)
{
gata=1;
cpt=capat;
for (i=1;i<cpt;i++)
if (v[i]<v[i+1])
{
aux=v[i], v[i]=v[i+1], v[i+1]=aux;
gata=0;
capat=i;
}
}
}
int main ()
{
citire ();
sort ();
bk (1);
if (pp==0)
fout<<"-1";
return 0;
}