Pagini recente » Cod sursa (job #264542) | Cod sursa (job #1843426) | Cod sursa (job #687463) | Cod sursa (job #2576187) | Cod sursa (job #3209773)
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream cin("loto.in");
ofstream cout("loto.out");
int v[605], sum;
vector <int> ans;
void bkt(int n, int s, int nre, int pz) {
if (s > sum)
return;
if (nre == 6) {
if (s == sum) {
for (auto x : ans)
cout << x << ' ';
exit(0);
}
return;
}
if (pz > n)
return;
for (int i = 0; i <= 6; i++) {
for (int j = 1; j <= i; j++)
ans.push_back(v[pz]);
bkt(n, s + v[pz] * i, nre + i, pz + 1);
for (int j = 1; j <= i; j++)
ans.pop_back();
}
}
int main() {
int n;
cin >> n >> sum;
for (int i = 1; i <= n; i++)
cin >> v[i];
bkt(n, 0, 0, 1);
cout << -1;
}