背包的解法solve();
function solve () {
let
total = parseInt(readline()), // 总流量
consume = readline().split(/\s+/).map(s => Number(s)), // 每个app消耗的流量coin = readline().split(/\s+/).map(s => Number(s)); // 每个app的金币数let buffer = [];
for (let i = 0; i < consume.length + 1; i++) {
buffer[i] = [0];
}
for (let w = 0; w < total + 1; w++) {
buffer[0][w] = 0;
}
for (let w = 1; w < total + 1; w++) {
for (let i = 1; i < consume.length + 1; i++) {
if (consume[i - 1] > w) {
buffer[i][w] = buffer[i - 1][w];
} else {
buffer[i][w] = Math.max(buffer[i - 1][w], coin[i - 1] + buffer[i - 1][w - consume[i-1]]);
}
}
}
let result = [];
let w = total;
for (let i = consume.length; i > 0; i--) {
if (buffer[i][w] === buffer[i-1][w]) {
continue;
} else {
result.push(i);
w -= consume[i - 1];
}
}
print(result.reverse().join(' '));
}