Problems
Tram
i give it function maxSatisfaction(N, M, P, passengers) { let dp = new Array(P + 1).fill(0);
for (let i = 1; i <= P; i++) {
dp[i] = dp[i - 1];
for (let j = 0; j < N; j++) {
let [ai, bi, ci, di] = passengers[j];
if (di === i) {
dp[i] = Math.max(dp[i], dp[ci] + ai);
} else if (di > i) {
dp[i] = Math.max(dp[i], dp[ci] + ai - bi);
}
}
}
return dp[P];
}
// Example usage: const N = 4; const M = 2; const P = 4; const passengers = [ [1, 3, 1, 2], [2, 4, 1, 3], [3, 5, 2, 4], [4, 2, 1, 4] ];
console.log(maxSatisfaction(N, M, P, passengers)); // Output: 7 but not worked. https://gbprowa.com/