Pagini recente » Cod sursa (job #2653831) | Cod sursa (job #2803233) | Cod sursa (job #648201) | Cod sursa (job #80042) | Cod sursa (job #498667)
Cod sursa(job #498667)
#include <stdio.h>
struct point {int inf,x1,x2,x3; point *leg;};
int n,s,elem[100],i,j,k,suma;
point *sume[1100001],*p,*pcompl;
void insereaza(int numar)
{
point *nou,*aa=sume[numar%1100000];
nou=aa;
while (nou!=NULL)
{
if (nou->inf==numar) return;
nou=nou->leg;
}
nou=new point;
nou->inf=numar;
nou->x1=elem[i]; nou->x2=elem[j]; nou->x3=elem[k];
nou->leg=sume[numar%1100000];
sume[numar%1100000]=nou;
}
point *cauta(int numarr)
{
point *aa=sume[numarr%1100000];
while (aa!=NULL)
{
if (aa->inf==numarr) return aa;
aa=aa->leg;
}
return NULL;
}
int main()
{
freopen("loto.in","r",stdin);
freopen("loto.out","w",stdout);
scanf("%d%d",&n,&s);
for (i=0;i<n;i++)
scanf("%d",&elem[i]);
for (i=0;i<n;i++)
for (j=0;j<n;j++)
for (k=0;k<n;k++)
{
suma=elem[i]+elem[j]+elem[k];
insereaza(suma);
}
for (i=0;i<1100000;i++)
{
p=sume[i];
while (p&&p->inf>0)
{
suma=p->inf;
if (s-suma>0)
{
pcompl=cauta(s-suma);
if (pcompl!=NULL)
{
printf("%d %d %d %d %d %d\n",p->x1,p->x2,p->x3,pcompl->x1,pcompl->x2,pcompl->x3);
return 0;
}
}
p=p->leg;
}
}
printf("-1\n");
return 0;
}