Pagini recente » Cod sursa (job #453818) | Cod sursa (job #1971044) | Istoria paginii utilizator/mai0neza | Cod sursa (job #597869) | Cod sursa (job #229213)
Cod sursa(job #229213)
#include<cstdio>
#include<algorithm>
using namespace std;
int sum[1000001],l;
struct poz{int sum,x,y,z;}p[1000001];
bool operator<(const poz &a, const poz &b)
{ return (a.sum<b.sum);}
int bsearch(int x)
{
int st=1,dr=l,mid;
while(st<=dr)
{ mid=(st+dr)/2;
if(x==p[mid].sum) return mid;
if(x>p[mid].sum)
st=mid+1;
else dr=mid-1;
}
return 0;
}
int main()
{ register int a[101],k,i,n,s,j,m;
freopen("loto.in","r",stdin);
freopen("loto.out","w",stdout);
scanf("%d%d",&n,&s);
for(i=1;i<=n;++i)
scanf("%d",&a[i]);
for(i=1;i<=n;++i)
for(j=i;j<=n;++j)
for(k=j;k<=n;++k)
p[++l].sum=a[i]+a[j]+a[k],
p[l].x=i,p[l].y=j,p[l].z=k;
sort(p+1,p+l);
for(i=1;i<=l;++i)
{ m=bsearch(s-p[i].sum);
if(m!=0)
{ printf("%d %d %d %d %d %d",a[p[i].x],a[p[i].y],a[p[i].z],a[p[m].x],a[p[m].y],a[p[m].z]);
return 0;
}
}
printf("-1");
return 0;
}