Solving Questions With Brainpower
You are given a 0-indexed 2D integer array questions where questions[i] = [points_i, brainpower_i].
The array describes the questions of an exam, where you have to process the questions in order starting from question 0 and decide whether to solve or skip each question.
- Solving question
iwill earn youpoints_ipoints, but you will be unable to solve each of the nextbrainpower_iquestions. - If you skip question
i, you get to make the decision on the next question.
Return the maximum points you can earn for the exam.
Example 1
Input
questions = [[3,2],[4,3],[4,4],[2,5]]Output
5The maximum points can be earned by solving questions 0 and 3 for a total of 3 + 2 = 5 points, and there is no way to earn 5 or more points otherwise.
Example 2
Input
questions = [[1,1],[2,2],[3,3],[4,4],[5,5]]Output
7The maximum points can be earned by skipping question 0, solving question 1, then solving question 4 for a total of 2 + 5 = 7 points.
Constraints
- 1 <= questions.length <= 10^5
- questions[i].length == 2
- 1 <= pointsi, brainpoweri <= 10^5