Pagini recente » Cod sursa (job #2741415) | Cod sursa (job #1726635) | Cod sursa (job #2050270) | Cod sursa (job #437219) | Cod sursa (job #849149)
Cod sursa(job #849149)
#include <cassert>
#include <cstdio>
#include <algorithm>
using namespace std;
int d[1000005][4],v[105];
int main()
{
int n=0,s=0,i=0,j=0,k=0,m=0,st=0,dr=0;
assert(freopen("loto.in","r",stdin));
assert(freopen("loto.out","w",stdout));
assert(scanf("%d%d",&n,&s));
for (i=0; i<n; ++i)
assert(scanf("%d",&v[i]));
sort(v,v+n);
for (i=0; i<n; ++i)
for (j=0; j<n; ++j)
for (k=0; k<n; ++k)
{
d[m][0]=v[i]+v[j]+v[k];
d[m][1]=v[i];
d[m][2]=v[j];
d[m][3]=v[k];
++m;
}
st=0;
dr=n*n*n-1;
while (st<=dr)
{
if (d[st][0]+d[dr][0]==s)
break;
if (d[dr][0]+d[dr][0]<s || d[st][0]+d[st][0]>s)
{
st=dr+1;
break;
}
if (d[st][0]+d[dr][0]<s)
++st;
else
--dr;
}
if (st<=dr)
assert(printf("%d %d %d %d %d %d\n",d[st][1],d[st][2],d[st][3],d[dr][1],d[dr][2],d[dr][3]));
else
assert(printf("-1\n"));
return 0;
}