Pagini recente » Cod sursa (job #1049737) | Cod sursa (job #2403146) | Cod sursa (job #2892835) | Cod sursa (job #1379485) | Cod sursa (job #2894666)
#include <fstream>
#include <unordered_set>
std::unordered_set<long long> hash(100100);
int v[101];
int main()
{
std::ifstream fin("loto.in");
std::ofstream fout("loto.out");
int n, s;
fin >> n >> s;
for (int i = 1; i <= n; ++i) fin >> v[i];
for (int i = 1; i <= n; ++i)
for (int j = i; j <= n; ++j)
for (int h = j; h <= n; ++h)
hash.insert(v[i] + v[j] + v[h]);
bool continua = true;
for (auto it : hash) {
if (!continua) break;
if (hash.find(s - it) != hash.end()) {
for (int i = 1; i <=n && continua; ++i)
for (int j = i; j <= n && continua; ++j)
for (int h = j; h <= n; ++h)
if (v[i] + v[j] + v[h] == s - it) {
fout << v[i] << " " << v[j] << " " << v[h] << " ";
continua = false;
break;
}
if (!continua) {
for (int i = 1; i <= n; ++i)
for (int j = i; j <= n; ++j)
for (int h = j; h <= n; ++h)
if (v[i] + v[j] + v[h] == it) {
fout << v[i] << " " << v[j] << " " << v[h];
}
}
}
}
if (continua) fout << -1;
return 0;
}