diff --git a/src/integerKnapsack.js b/src/integerKnapsack.js index 7138550..09c7b73 100644 --- a/src/integerKnapsack.js +++ b/src/integerKnapsack.js @@ -7,10 +7,11 @@ const integerKnapsack = (v, w, n, W, m = new w.constructor(W + 1).fill(0)) => { assert(m.length >= W + 1); for (let i = 0; i < n; ++i) { const x = w[i]; + const y = v[i]; assert(Number.isInteger(x) && x >= 0 && x <= W); const s = W - x; for (let j = 0; j <= s; ++j) { - m[j] = Math.max(m[j], m[j + x] + v[i]); + m[j] = Math.max(m[j], m[j + x] + y); } }