Pagini recente » Cod sursa (job #3124243) | Cod sursa (job #216428) | Cod sursa (job #2759351) | Cod sursa (job #2353672) | Cod sursa (job #1232608)
#include <fstream>
#include <unordered_map>
using namespace std;
struct Triplet {
int x, y, z;
Triplet(int nx, int ny, int nz) {
x = nx;
y = ny;
z = nz;
}
};
int N, S, a[105];
unordered_map<int, Triplet> sum_map;
ifstream fin("loto.in");
ofstream fout("loto.out");
int main() {
fin >> N >> S;
for (int i = 0; i < N; ++i)
fin >> a[i];
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
for (int k = 0; k < N; ++k) {
int crt_sum = a[i] + a[j] + a[k];
sum_map.insert(make_pair(crt_sum, Triplet(a[i], a[j], a[k])));
auto it = sum_map.find(S - crt_sum);
if (it != sum_map.end()) {
fout << a[i] << " "
<< a[j] << " "
<< a[k] << " "
<< it->second.x << " "
<< it->second.y << " "
<< it->second.z << "\n";
return 0;
}
}
fout << "-1\n";
return 0;
}