Pagini recente » Cod sursa (job #456187) | Cod sursa (job #668308) | Cod sursa (job #2551900) | Cod sursa (job #1390310) | Cod sursa (job #498659)
Cod sursa(job #498659)
#include <stdio.h>
struct point {long long inf,x1,x2,x3; point *leg;};
long long n,s,elem[100],i,j,k,suma;
point *sume[1100000],*p,*pcompl;
void insereaza(long long numar)
{
point *nou,*aa=sume[numar%1100000];
nou=aa;
while (nou)
{
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(long long numarr)
{
point *aa=sume[numarr%1100000];
while (aa)
{
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("%lld",&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)
{
suma=p->inf;
pcompl=cauta(s-suma);
if (pcompl)
{
printf("%lld %lld %lld %lld %lld %lld\n",p->x1,p->x2,p->x3,pcompl->x1,pcompl->x2,pcompl->x3);
return 0;
}
p=p->leg;
}
}
printf("-1\n");
return 0;
}