Pagini recente » Cod sursa (job #2503136) | Cod sursa (job #3156944) | Cod sursa (job #2754832) | Istoria paginii preoni-2007/clasament | Cod sursa (job #1789078)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
struct suma
{
suma(int tx, int ty, int tz)
{
x = tx;
y = ty;
z = tz;
s = tx + ty + tz;
}
suma()
{
}
int x, y, z;
int s;
};
ifstream in("loto.in");
ofstream out("loto.out");
int n, s;
int v[105];
suma sum[105 * 105 * 105];
void citire()
{
in >> n >> s;
for(int i = 1; i <= n; ++i)
in >> v[i];
}
bool comp(suma x, int val)
{
if(x.s < val) return true;
return false;
}
bool cmp(suma x, suma y)
{
if(x.s < y.s)
return true;
return false;
}
void rezolvare()
{
int pos = 0;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
for(int k = 1; k <= n; ++k)
{
sum[pos] = suma(v[i], v[j], v[k]);
pos++;
}
sort(sum, sum + pos, cmp);
int rasp[6];
rasp[0] = -1;
for(int i = 0; i < pos; ++i)
{
int rest = s - sum[i].s;
auto it = lower_bound(sum, sum + pos, rest, comp);
if(it->s == rest)
{
rasp[0] = sum[i].x;
rasp[1] = sum[i].y;
rasp[2] = sum[i].z;
rasp[3] = it->x;
rasp[4] = it->y;
rasp[5] = it->z;
}
}
if(rasp[0] != -1)
{
for(int i = 0; i < 6; ++i)
out << rasp[i] << " ";
}
else
out << -1;
}
int main()
{
citire();
rezolvare();
return 0;
}