function completeKnapsack(weights, values, W) {
    var n = weights.length,
        dp = new Array(W + 1).fill(0);

    for (let i = 0; i < n; i++) {
        if (weights[i] < j) {
            dp[j] = Math.max(dp[j], dp[j - weights[i]] + values[i]);
        }
    }
    return dp[W];
}
