Pagini recente » Cod sursa (job #430688) | Cod sursa (job #1179691) | Cod sursa (job #874462) | Cod sursa (job #668260) | Cod sursa (job #3031012)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("loto.in");
ofstream fout("loto.out");
int v[101],nw,n,S;
struct pereche
{
int x,m;
bool operator< (pereche& b)
{
return x < b.x;
}
} w[101*101*101];
int main()
{
int i,j,k,st,dr,mij,s;
fin >> n >> S;
for (i=0; i<n; i++)
fin >> v[i];
for (i=0; i<n; i++)
for (j=i; j<n; j++)
for (k=j; k<n; k++)
w[nw++] = { v[i]+v[j]+v[k], i*10000+j*100+k };
sort(w, w+nw);
for (i=0; i<nw; i++)
{
st=0;
dr=nw-1;
while (st<=dr)
{
mij=(st+dr)/2;
s = w[i].x + w[mij].x;
if (s == S)
{
int x[6];
x[0] = w[i].m % 100;
x[1] = w[i].m / 100 % 100;
x[2] = w[i].m / 10000 % 100;
x[3] = w[mij].m % 100;
x[4] = w[mij].m / 100 % 100;
x[5] = w[mij].m / 10000 % 100;
sort(x, x+6);
for (i=0; i<6; i++)
fout << v[x[i]] << ' ';
return 0;
}
if (s < S)
st = mij+1;
else
dr = mij-1;
}
}
fout << -1;
return 0;
}