You are given a 0-indexed 2D array questions where questions[i] = [points_i, brainpower_i]. You go through the exam in order and for each question decide to solve it or skip it. Solving question i earns points_i but leaves you unable to solve the next brainpower_i questions. Skipping it lets you decide on the next question. Return the maximum points you can earn.
You are given a 0-indexed 2D array questions where questions[i] = [points_i, brainpower_i]. You go through the exam in order and for each question decide to solve it or skip it. Solving question i earns points_i but leaves you unable to solve the next brainpower_i questions. Skipping it lets you decide on the next question. Return the maximum points you can earn.
Example 1:
Input: {"questions":[[3,2],[4,3],[4,4],[2,5]]}
Output: 5
Constraints:
1≤questions.length≤105
questions[i].length=2
1≤pointsi,brainpoweri≤105
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"questions":[[3,2],[4,3],[4,4],[2,5]]}
dp[i] = best score from question i to the end. Past the last question there is nothing left, so dp[4] = 0. Fill dp from right to left.
exam questions 0..4 (points on top, brainpower below)