Pagini recente » Cod sursa (job #588704) | Cod sursa (job #2095923) | Cod sursa (job #588256) | Cod sursa (job #2094061) | Cod sursa (job #3279644)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
const int MAX_N = 100;
int n, s;
int v[MAX_N], sol[6];
bool gasit = false;
void bkt(int poz, int sum) {
if (gasit) return;
if (poz == 6) {
if (sum == s) {
gasit = true;
}
return;
}
for (int i = 0; i < n; i++) {
if (sum + v[i] > s) continue;
sol[poz] = v[i];
bkt(poz + 1, sum + v[i]);
if (gasit) return;
}
}
int main() {
fin >> n >> s;
for (int i = 0; i < n; i++) {
fin >> v[i];
}
sort(v, v + n, greater<int>());
bkt(0, 0);
if (gasit) {
for (int i = 0; i < 6; i++) {
fout << sol[i] << " ";
}
} else {
fout << "-1";
}
return 0;
}