Pagini recente » Cod sursa (job #1858703) | Cod sursa (job #2415768) | Cod sursa (job #1085692) | Cod sursa (job #1282346) | Cod sursa (job #1553489)
#include <iostream>
#include <fstream>
#include <vector>
#include <unordered_map>
#include <tuple>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
int main()
{
int N, S;
vector<int> num;
fin >> N >> S;
num.resize(N);
for (int i = 0; i < N; ++i)
fin >> num[i];
unordered_map<int, tuple<int, int, int>> m;
for (auto n1 = num.begin(); n1 != num.end(); ++n1)
{
for (auto n2 = num.begin(); n2 != num.end(); ++n2)
{
for (auto n3 = num.begin(); n3 != num.end(); ++n3)
{
m[*n1 + *n2 + *n3] = make_tuple(*n1, *n2, *n3);
}
}
}
for (auto n1 = num.begin(); n1 != num.end(); ++n1)
{
for (auto n2 = num.begin(); n2 != num.end(); ++n2)
{
for (auto n3 = num.begin(); n3 != num.end(); ++n3)
{
auto it = m.find(S - *n1 - *n2 - *n3);
if (it != m.end())
{
auto tup = it->second;
fout << *n1 << ' ' << *n2 << ' ' << *n3 << ' ' << get<0>(tup) << ' ' << get<1>(tup) << ' ' << get<2>(tup);
return 0;
}
}
}
}
fout << -1;
return 0;
}