Pagini recente » Cod sursa (job #515422) | Cod sursa (job #2144612) | Cod sursa (job #1824926) | Cod sursa (job #1870459) | Cod sursa (job #66095)
Cod sursa(job #66095)
#include<stdio.h>
long a[101],s;
int n,gasit=0,q[101];
void citire()
{
freopen("loto.in","r",stdin);
scanf("%d%ld", &n, &s);
for (int i=0; i<n; i++)
scanf("%ld", &a[i]);
fclose(stdin);
}
void afiseaza()
{
freopen("loto.out","w",stdout);
for (int i=0; i<6; i++)
printf("%ld ",a[q[i]]);
gasit=1;
fclose(stdout);
}
void back(int w)
{
if (w>5)
{
if (s==0)
afiseaza();
}
else {
for (int i=n-1; i>=0; i--)
{
s-=a[i];
q[w]=i;
if (s>=0 && gasit==0)
back(w+1);
s+=a[i];
}
}
}
int main()
{
citire();
back(0);
if (gasit==0)
{
freopen("loto.out","w",stdout);
printf("-1");
fclose(stdout);
}
return 0;
}