Pagini recente » Cod sursa (job #2200583) | Cod sursa (job #2533186) | Cod sursa (job #699137) | Cod sursa (job #2367647) | Cod sursa (job #1438177)
#include <cstdio>
#include <algorithm>
using namespace std;
int st,dr;
struct val
{
int a1,a2,a3,a123;
};
bool cmp(val x, val y)
{
return x.a123<y.a123;
}
val sol[1000001];
int v[101];
void bs(int s)
{
st=1;
while(st<=dr)
{
if(sol[st].a123+sol[dr].a123==s)
break;
else
{
if(sol[st].a123+sol[dr].a123>s)
dr--;
else
st++;
}
}
}
int main()
{
freopen("loto.in", "r",stdin);
freopen("loto.out", "w",stdout);
int n,s,i,x=0,k,j;
scanf("%d%d", &n, &s);
for(i=1; i<=n; i++)
scanf("%d", &v[i]);
for(i=1; i<=n; i++)
{
for(k=i; k<=n; k++)
{
for(j=k; j<=n; j++)
{
sol[++x].a1=v[i];
sol[x].a2=v[k];
sol[x].a3=v[j];
sol[x].a123=v[i]+v[j]+v[k];
}
}
}
sort(sol+1, sol+x+1,cmp);
dr=x;
bs(s);
if(st<=dr)
printf("%d %d %d %d %d %d", sol[st].a1, sol[st].a2, sol[st].a3, sol[dr].a1, sol[dr].a2, sol[dr].a3);
else
printf("-1");
return 0;
}