Pagini recente » Cod sursa (job #1822264) | Cod sursa (job #3328) | Cod sursa (job #3219348) | Cod sursa (job #3249996) | Cod sursa (job #1541690)
#include <vector>
#include <iostream>
#include <unordered_map>
#include <tuple>
#include <fstream>
using namespace std;
int main() {
#ifdef INFOARENA
ifstream cin("loto.in");
ofstream cout("loto.out");
#endif
int N, S;
vector<int> numbers;
cin >> N >> S;
numbers.resize(N);
for (int i = 0; i < N; ++i) {
cin >> numbers[i];
}
unordered_map<int, tuple<int, int, int>> m;
for (auto n1 = numbers.begin(); n1 != numbers.end(); ++n1) {
for (auto n2 = n1; n2 != numbers.end(); ++n2) {
for (auto n3 = n2; n3 != numbers.end(); ++n3) {
m[*n1 + *n2 + *n3] = make_tuple(*n1, *n2, *n3);
}
}
}
for (auto n1 = numbers.begin(); n1 != numbers.end(); ++n1) {
for (auto n2 = n1; n2 != numbers.end(); ++n2) {
for (auto n3 = n2; n3 != numbers.end(); ++n3) {
auto it = m.find(S - (*n1 + *n2 + *n3));
if (it != m.end()) {
auto tup = it->second;
cout << get<0>(tup) << ' ' << get<1>(tup) << ' ' << get<2>(tup) << ' '
<< *n1 << ' ' << *n2 << ' ' << *n3 << endl;
return 0;
}
}
}
}
cout << -1 << endl;
return 0;
}