Pagini recente » Cod sursa (job #688722) | Cod sursa (job #655503) | Cod sursa (job #2726136) | Cod sursa (job #2578453) | Cod sursa (job #3132137)
#include <fstream>
#include <iostream>
#include <algorithm>
std::ifstream in("loto.in");
std::ofstream out("loto.out");
struct haz
{
int sum, x, y, z;
}w[400001];
int hazz(haz x, haz y)
{
return x.sum < y.sum;
}
int n, s, o[101], nr;
void read()
{
in >> n >> s;
for (int i = 1; i <= n; i++)
in >> o[i];
}
int main()
{
read();
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++)
for (int k = j; k <= n; k++)
{
w[++nr].sum = o[i] + o[j] + o[k];
w[nr].x = o[i];
w[nr].y = o[j];
w[nr].z = o[k];
}
std::sort(w + 1, w + nr + 1, hazz);
int st = 1, dr = nr;
while (st <= dr)
{
if (w[st].sum + w[dr].sum > s)
dr--;
else
if (w[st].sum + w[dr].sum < s)
st++;
else break;
}
if (st > dr)
out << -1;
else
out << w[st].x << " " << w[st].y << " " << w[st].z << " " << w[dr].x << " " << w[dr].y << " " << w[dr].z;
}