Pagini recente » Cod sursa (job #561073) | Cod sursa (job #2849459) | Cod sursa (job #429938) | Cod sursa (job #3039400) | Cod sursa (job #3005583)
#include<bits/stdc++.h>
#define NMax 1000001
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
int n,S,v[101],lgw,poz;
struct elem
{
int sum;
int x,y,z;
}w[NMax];
bool caut_bin(int x,int &poz)
{
int st=1,dr=lgw;
while(st<=dr)
{
int mij=(st+dr)/2;
if(x==w[mij].sum)
{
poz=mij;
return 1;
}
else if(x<w[mij].sum)
dr=mij-1;
else st=mij+1;
}
return 0;
}
bool comp(elem a, elem b)
{
if(a.sum>b.sum)
return 1;
else if(a.x>b.x)
return 1;
else if(a.y>b.y)
return 1;
else if(a.z>b.z)
return 1;
return 0;
}
int main()
{
fin>>n>>S;
for(int i=1; i<=n; i++)
fin>>v[i];
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
for(int k=1; k<=n; k++)
{
w[++lgw].sum=v[i]+v[j]+v[k];
w[lgw].x=v[i];
w[lgw].y=v[j];
w[lgw].z=v[k];
}
sort(w+1,w+lgw+1,comp);
for(int i=1; i<=lgw; i++)
if(caut_bin(S-w[i].sum,poz))
{
fout<<w[i].x<<' '<<w[i].y<<' '<<w[i].z<<' '<<w[poz].x<<' '<<w[poz].y<<' '<<w[poz].z;
return 0;
}
fout<<-1;
return 0;
}