Pagini recente » Cod sursa (job #2207170) | Cod sursa (job #1564427) | Cod sursa (job #1659970) | Cod sursa (job #1734867) | Cod sursa (job #927970)
Cod sursa(job #927970)
#include<cstdio>
#include<vector>
#include<utility>
#include<algorithm>
#define nmax 110
using namespace std;
int n,s,v[nmax],i,j,k,x,st,dr,m;
vector<pair<int,pair<int,pair<int,int> > > >V;
vector<pair<int,pair<int,pair<int,int> > > >::iterator it;
int main()
{
freopen("loto.in","r",stdin);
freopen("loto.out","w",stdout);
scanf("%d%d", &n, &s);
for(i=1;i<=n;++i)scanf("%d", &v[i]);
for(i=1;i<=n;++i)
for(j=i;j<=n;++j)
for(k=j;k<=n;++k)
V.push_back(make_pair(v[i]+v[j]+v[k],make_pair(v[i],make_pair(v[j],v[k]))));
sort(V.begin(),V.end());
for(it=V.begin();it!=V.end();++it)
{
x=s-it->first;
st=0;dr=V.size()-1;
for(;st<=dr;)
{
m=(st+dr)/2;
if(V[m].first==x)
{
printf("%d %d %d %d %d %d ", it->second.first, it->second.second.first, it->second.second.second, V[m].second.first, V[m].second.second.first, V[m].second.second.second);
return 0;
}
if(V[m].first<x)dr=m-1;
else st=m+1;
}
}
printf("-1\n");
return 0;
}