Pagini recente » Cod sursa (job #2391153) | Cod sursa (job #823047) | Cod sursa (job #2464617) | Cod sursa (job #1663986) | Cod sursa (job #3130416)
#include <fstream>
#include <algorithm>
#include<stack>
typedef long long nat;
std::ifstream fin("loto.in");
std::ofstream fout("loto.out");
#define spush(s, number, amount) for (int asdf = 0; asdf < amount; ++asdf) s.push(number)
#define spop(s, amount) for (int asdf = 0; asdf < amount; ++asdf) s.pop()
#define sprint(s) while (s.empty() == false) { fout << s.top() << " "; s.pop(); }
std::stack<nat> rasp;
bool good = false;
void loto(nat*const vend, nat*const v, nat suma, int remaining = 6) {
if (suma == 0 and remaining == 0) {
if (good == false)
sprint(rasp)
good = true;
return;
}
if (v == vend)
return;
if (suma / *v > 0) {
for (int i = std::min((nat)remaining, suma / *v); i > 0; --i) {
spush(rasp, *v, i);
loto(vend, v - 1, suma - *v * i, remaining - i);
if (good == true)
return;
spop(rasp, i);
}
}
if (good == true)
return;
loto(vend, v - 1, suma, remaining);
}
int main() {
int n;
nat v[101], s;
fin >> n >> s;
int cn = n;
while (cn--) {
fin >> v[n - cn];
}
std::sort(v + 1, v + n + 1);
loto(v, v + n, s);
if (good == false)
fout << -1;
return 0;
}