Choose Exam Questions with Forced Skips. Process questions in their given order. Solving questions[i]=[points,brainpower] earns points but forces you to skip the next brainpower questions. Skipping voluntarily earns nothing and allows considering the next question. Return the maximum obtainable total.
### Problem
An exam contains questions in a fixed order. `questions[i] = [points, brainpower]` describes question `i`. Solving it earns `points` but prevents solving the next `brainpower` questions. You may instead skip it voluntarily and consider the following question. Return the largest total score you can earn while following these rules.
```cpp
class Solution {
public:
long long mostPoints(vector<vector<int>>& questions);
};
```
### Examples
**Example 1:**
```text
questions = [[5,1],[6,1],[4,1]]
Output: 9
Explanation: Solve indices 0 and 2 for 5+4 points.
```
**Example 2:**
```text
questions = [[2,3],[9,1],[3,1]]
Output: 9
Explanation: Skipping index 0 and solving index 1 is best.
```
### Constraints
- `1 <= questions.length <= 10^5`.
- Every row has two integers, each in `[1,10^5]`.
### Clarifying Questions
The next candidate after solving i is i+brainpower+1. Forced skips beyond the end simply finish the exam.
```hint Inspect the structure
What is the best score available from a suffix when its first question is either skipped or solved?
```
### Reasoning checkpoints
- Respect the forced skip after every solved question and distinguish it from a voluntary skip.
- Prove that the chosen score is maximal over every valid sequence of solve-or-skip decisions.
- Handle skips beyond the final question and scores that exceed 32-bit range.
### Optional extensions
How could you also return one optimal set of solved question indices?
Overview: Choose Exam Questions with Forced Skips. Process questions in their given order. Solving questions[i]=[points,brainpower] earns points but forces you to skip the next brainpower questions. Skipping voluntarily earns nothing and allows considering the next question. Return the maximum obtainable total.
An exam contains questions in a fixed order. questions[i] = [points, brainpower] describes question i. Solving it earns points but prevents solving the next brainpower questions. You may instead skip it voluntarily and consider the following question. Return the largest total score you can earn while following these rules.
class Solution {
public:
long long mostPoints(vector<vector<int>>& questions);
};
Examples
Example 1:
questions = [[5,1],[6,1],[4,1]]
Output: 9
Explanation: Solve indices 0 and 2 for 5+4 points.
Example 2:
questions = [[2,3],[9,1],[3,1]]
Output: 9
Explanation: Skipping index 0 and solving index 1 is best.
Constraints
1 <= questions.length <= 10^5
.
Every row has two integers, each in
[1,10^5]
.
Clarifying Questions Guidance
The next candidate after solving i is i+brainpower+1. Forced skips beyond the end simply finish the exam.
Reasoning checkpoints
Respect the forced skip after every solved question and distinguish it from a voluntary skip.
Prove that the chosen score is maximal over every valid sequence of solve-or-skip decisions.
Handle skips beyond the final question and scores that exceed 32-bit range.
Optional extensions
How could you also return one optimal set of solved question indices?