Pagini recente » Cod sursa (job #559263) | Cod sursa (job #1597593) | Cod sursa (job #2893334) | Cod sursa (job #678630) | Cod sursa (job #2895813)
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
struct jumate
{
int a, b, c;
};
unordered_map <int, jumate> sum;
int main()
{
int n, suma, i, q, w , e, temp;
f >> n >> suma;
int v[n+1];
for(i = 0; i < n; i++)
{
f >> v[i];
}
for(q = 0; q < n; q++)
for(w = q; w < n; w++)
for(e = w; e < n; e++)
{
sum.insert(pair<int, jumate>(v[q] + v[w] + v[e], {v[q], v[w], v[e]}));
}
bool ok = false;
for(auto it = sum.begin(); it != sum.end() && ok == false; it++)
{
temp = suma - it->second.a - it->second.b - it->second.c;
if(sum.find(temp) != sum.end())
{
ok = true;
g << sum[temp].a << " " << sum[temp].b << " " << sum[temp].c << " " << it->second.a << " " << it->second.b << " " << it->second.c;
}
}
if(ok == false)
g << -1;
return 0;
}