Pagini recente » Cod sursa (job #1476022) | Cod sursa (job #1875055) | Cod sursa (job #991960) | Cod sursa (job #2963055) | Cod sursa (job #3252253)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
struct Valori {
int a, b, c;
};
int n, s, i, j, k, a[102];
unordered_map<int, Valori> fr;
int main() {
fin >> n >> s;
for(i = 1; i <= n; i++) fin >> a[i];
for(i = 1; i <= n; i++) {
for(j = 1; j <= n; j++) {
for(k = 1; k <= n; k++) fr[a[i] + a[j] + a[k]] = {a[i], a[j], a[k]};
}
}
for(i = 1; i <= n; i++) {
for(j = 1; j <= n; j++) {
for(k = 1; k <= n; k++) {
int sum = a[i] + a[j] + a[k];
if(sum <= s) {
auto it = fr.find(s - sum);
if(it != fr.end()) {
fout << a[i] << " " << a[j] << " " << a[k] << " ";
Valori v = it->second;
fout << v.a << " " << v.b << " " << v.c;
return 0;
}
}
}
}
}
fout << "-1";
return 0;
}