function knapsack(weights, values, numbers, m) {
    var cnt = 0;
    var w = [];
    var v = [];
    var n = weights.length;
    for (let i = 0; i < n; i++) {
        //cin>>W>>V>>C;
        var W = weights[i];
        var V = values[i];
        var C = numbers[i];
        for (let j = 1; ; j *= 2) {
            if (C >= j) {
                w[cnt] = j * W;
                v[cnt] = j * V;
                C -= j;
                cnt++;
            } else {
                w[cnt] = C * W;
                v[cnt] = C * V;
                cnt++;
                break;
            }
        }
    }
    var dp = new Array(m + 1).fill(0);
    for (let i = 0; i < cnt; i++) {
        for (let j = m; j >= w[i]; j--) {
            dp[j] = Math.max(dp[j], dp[j - w[i]] + v[i]);
        }
    }

    return dp[m];
}
