Pagini recente » Cod sursa (job #1828560) | Cod sursa (job #316976) | Cod sursa (job #2722206) | Cod sursa (job #292415) | Cod sursa (job #2309494)
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
const int NMAX = 110;
struct val
{
int cost, x, y, z;
val()
{
this->cost = this->x = this->y = this->z = 0;
}
val(const int &cost, const int &x, const int &y, const int &z)
{
this->cost = cost;
this->x = x;
this->y = y;
this->z = z;
}
inline bool operator<(const val &other) const
{
return this->cost < other.cost;
}
};
vector <val> a;
int n, s, v[NMAX];
int main()
{
ifstream fin("loto.in");
ofstream fout("loto.out");
fin >> n >> s;
for (int i = 1;i <= n;++i)
fin >> v[i];
for (int i = 1;i <= n;++i)
for (int j = i;j <= n;++j)
for (int k = j;k <= n;++k)
{
int aux = v[i] + v[j] + v[k];
a.push_back(val(aux, v[i], v[j], v[k]));
}
sort(a.begin(), a.end());
int st = 0, dr = a.size() - 1;
while (st < dr)
{
if (a[st].cost + a[dr].cost < s)
++st;
else if (a[st].cost + a[dr].cost > s)
--dr;
else
{
fout << a[st].x << " " << a[st].y << " " << a[st].z << " " << a[dr].x << " " << a[dr].y << " " << a[dr].z << "\n";
return 0;
}
}
fout << -1 << "\n";
fin.close();
fout.close();
return 0;
}