# Cod sursa(job #1165180)

Utilizator Data 2 aprilie 2014 15:43:00 Loto 50 cpp done Arhiva de probleme 1.69 kb
``````#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n,s,sp,v[101];
vector<int> H[666015];
inline int h(int x)
{
return x%666013;
}
void insert(int x)
{
H[h(x)].push_back(x);
}
inline bool verif(int suma)
{
for(int i=1;i<=H[h(suma)].size();++i)
{
if(H[h(suma)][i]==suma) return 1;
}
return 0;
}
int main()
{
freopen("loto.in","r",stdin);
freopen("loto.out","w",stdout);
scanf("%d%d",&n,&s);
for(int i=1;i<=n;++i)
{
scanf("%d",&v[i]);
}
for(int i=1;i<=n;++i)
{
for(int j=1;j<=n;++j)
{
for(int k=1;k<=n;++k)
{
insert(v[i]+v[j]+v[k]);
}
}
}
for(int i=1;i<=n;++i)
{
for(int j=1;j<=n;++j)
{
for(int k=1;k<=n;++k)
{
sp=s-v[i]-v[k]-v[j];
if(verif(sp)==1)
{
printf("%d %d %d ",v[i],v[j],v[k]);
for(int i2=1;i2<=n;++i2)
{
for(int j2=1;j2<=n;++j2)
{
for(int k2=1;k2<=n;++k2)
{
if(v[i2]+v[j2]+v[k2]==sp)
{
printf("%d %d %d",v[i2],v[j2],v[k2]);
return 0;
}
}
}
}
return 0;
}
}
}
}
printf("-1");
return 0;
}
``````