Pagini recente » Cod sursa (job #3227147) | Cod sursa (job #824638) | Cod sursa (job #1593037) | Cod sursa (job #295668) | Cod sursa (job #3131700)
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <vector>
//std::ifstream fin("C:\\Users\\DelMX\\OneDrive\\Sharing\\tema-sd-3\\loto.in");
//std::ofstream fout("C:\\Users\\DelMX\\OneDrive\\Sharing\\tema-sd-3\\loto.out");
std::ifstream fin("loto.in");
std::ofstream fout("loto.out");
class firstThree {
public:
int x, y, z;
};
int main() {
int n, s, x;
std::vector<int> v;
std::unordered_map<int, firstThree> m;
fin >> n >> s;
for (int i = 0; i < n; ++i) {
fin >> x;
v.push_back(x);
}
for (int i = 0; i < n; ++i) {
for (int j = i; j < n; ++j) {
for (int d = j; d < n; ++d) {
int suma = v[i] + v[j] + v[d];
firstThree pereche;
pereche.x = v[i];
pereche.y = v[j];
pereche.z = v[d];
m[suma] = pereche;
}
}
}
bool ok = false;
for (auto it = m.begin(); it != m.end(); ++it) {
if (m.find(s - it->first) != m.end()) {
fout << m[s - it->first].x << " ";
fout << m[s - it->first].y << " ";
fout << m[s - it->first].z << " ";
fout << m[it->first].x << " ";
fout << m[it->first].y << " ";
fout << m[it->first].z;
ok = true;
break;
}
}
if (!ok) {
fout << -1;
}
return 0;
}