Pagini recente » Utilizatori inregistrati la ONIS 2014, Runda 3 | Cod sursa (job #2965492) | Cod sursa (job #346383) | Cod sursa (job #2503134) | Cod sursa (job #981833)
Cod sursa(job #981833)
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=110;
const int MAXB=1000010;
int n,s,nrb;
int v[MAXN];
struct loto
{
int s,i,j,k;
};
loto b[MAXB];
void read()
{
freopen("loto.in","r",stdin);
scanf("%d%d",&n,&s);
for (int i=1; i<=n; ++i)
scanf("%d",&v[i]);
}
int binary_search(int low, int high, int value)
{
int mid;
while (low<=high)
{
mid=(low+high)/2;
if (b[mid].s==value)
return mid;
else if (value<b[mid].s)
high=mid-1;
else if (value>b[mid].s)
low=mid+1;
}
return 0;
}
inline bool cmp(loto a, loto b)
{
return a.s<b.s;
}
void solve()
{
freopen("loto.out","w",stdout);
int i,j,k;
for (i=1; i<=n; ++i)
{
for (j=i; j<=n; ++j)
{
for (k=j; k<=n; ++k)
{
++nrb;
b[nrb].s=v[i]+v[j]+v[k];
b[nrb].i=v[i];
b[nrb].j=v[j];
b[nrb].k=v[k];
}
}
}
sort(b+1,b+nrb+1,cmp);
i=j=0;
for (i=1; i<=nrb; ++i)
{
j=binary_search(1,nrb,s-b[i].s);
if (j)
{
printf("%d %d %d %d %d %d\n",b[i].i,b[i].j,b[i].k,b[j].i,b[j].j,b[j].k);
return;
}
}
printf("-1\n");
}
int main()
{
read();
solve();
return 0;
}