#P10108. [GESP202312 六级] 闯关游戏
[GESP202312 六级] 闯关游戏
Background
Related multiple-choice and true/false questions: https://ti.luogu.com.cn/problemset/1138.
Problem Description
You have arrived at a level-clearing game.
This game has a total of levels. Each level has passages. You need to choose one passage to move to later levels. The -th passage lets you move forward by levels. That is, if you are currently at level , then after choosing the -th passage, you will go directly to level (in particular, if , then you clear the game). Also, when you successfully leave level , you will gain points.
At the start of the game, you are at level . What is the maximum total score you can get when you clear the game?
Input Format
The first line contains two integers and , representing the number of levels and the number of passages in each level.
The next line contains integers separated by single spaces. It is guaranteed that .
The next line contains integers separated by single spaces. It is guaranteed that .
Output Format
Output one integer in one line, representing the maximum score you can obtain when you clear the game.
6 2
2 3
1 0 30 100 30 30
131
6 2
2 3
1 0 30 100 30 -1
101
Hint
Sample Explanation 1
You can choose the -st passage at level , gain point, and arrive at level . Then choose the -th passage, gain points, and arrive at level . Finally, choose any passage, and you can gain points and clear the game. In this way, the total score is .
Sample Explanation 2
Note that the scores of some levels may be negative.
Constraints
For of the testdata, it is guaranteed that .
For of the testdata, it is guaranteed that and .
For all testdata, it is guaranteed that and .
Translated by ChatGPT 5