Pagini recente » Cod sursa (job #2067037) | Cod sursa (job #1629528) | Cod sursa (job #2031752) | Cod sursa (job #1922663) | Cod sursa (job #2540529)
#include <bits/stdc++.h>
using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");
int n,a[101],s;
int ok,sol[7];
void cauta(int pozSol=1,int suma=0)
{
if(pozSol>6)
{
if(suma==s)
ok=1;
else
ok=-1;
return;
}
for(int i=n;i>=1 && !ok;i--)
{
if(suma+a[i]>s)
continue;
sol[pozSol]=a[i];
cauta(pozSol+1,suma+a[i]);
}
}
int main()
{
in>>n>>s;
for(int i=1;i<=n;i++)
in>>a[i];
sort(a+1,a+1+n);
cauta();
if(ok==-1)
out<<ok;
else
for(int i=1;i<=6;i++)
out<<sol[i]<<' ';
return 0;
}