Pagini recente » Cod sursa (job #2450886) | Cod sursa (job #2974165) | Cod sursa (job #1925810) | Cod sursa (job #2116214) | Cod sursa (job #1441311)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
struct aaa
{
int f;
int a, b, c;
};
int a[101];
aaa b[2000001];
bool c(aaa x,aaa y)
{
if (x.f < y.f)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
ifstream in("loto.in");
ofstream out("loto.out");
int i,s, n,j,tot=0,k,inceput,sfarsit,mij,h[7];
in >> n;
in >> s;
for (i = 1; i <= n; i++)
{
in >> a[i];
}
sort(a + 1, a + n + 1);
for (i = 1; i <= n; i++)
{
for (j = i; j <= n; j++)
{
for (k = j; k <= n; k++)
{
tot++;
b[tot].f = a[i] + a[j] + a[k];
b[tot].a = a[i];
b[tot].b = a[j];
b[tot].c = a[k];
}
}
}
sort(b + 1, b + tot + 1, c);
for (i = 1; i <= tot; i++)
{
inceput = 1;
sfarsit = tot;
while (inceput <= sfarsit)
{
mij = (inceput + sfarsit) / 2;
if (b[i].f + b[mij].f < s)
{
inceput = mij + 1;
}
else if (b[i].f + b[mij].f > s)
{
sfarsit = mij - 1;
}
else
{
h[1] = b[i].a;
h[2] = b[i].b;
h[3] = b[i].c;
h[4] = b[mij].a;
h[5] = b[mij].b;
h[6] = b[mij].c;
sort(h + 1, h + 7);
for (i = 1; i <= 6; i++)
{
out << h[i] << " ";
}
return 0;
}
}
}
out << "-1";
}