#P10914. [蓝桥杯 2024 国 B] 跳石头
[蓝桥杯 2024 国 B] 跳石头
Problem Description
Xiaoming is playing a small jumping-stones game with his friends. There are stones in a row, numbered from to . The -th stone has a positive integer weight value written on it.
If at some moment Xiaoming is on stone , then he may choose to jump to stone (provided that ), or jump to stone (provided that ). If there is no stone he can jump to, the game ends.
Suppose Xiaoming chooses to start jumping from stone . If a stone may be visited by Xiaoming (where “visited” means that there exists some moment when Xiaoming is on this stone), then the weight value of this stone is included in the score set . Then Xiaoming’s score when starting from stone is .
For example, if Xiaoming starts from stone and the weight values on all stones that may be visited are , then and the score is . Xiaoming may choose any stone to start from. Please compute the maximum score Xiaoming can obtain.
Input Format
The input has lines.
The first line contains a positive integer .
The second line contains positive integers , separated by spaces.
Output Format
The output has line, containing one integer, which is the answer.
5
4 3 5 2 1
4
Hint
Sample Explanation
Starting from the first stone gives the maximum score. The possible paths are as follows:
- Stone stone : choose to jump from stone to stone .
- Stone stone stone : first choose to jump from stone to stone , then choose to jump from stone to stone .
- Stone stone stone : first choose to jump from stone to stone , then choose to jump from stone to stone .
Therefore, the set of weight values of all stones that may be visited is , and the score is .
Constraints
For of the testdata, it is guaranteed that .
For of the testdata, it is guaranteed that and .
Translated by ChatGPT 5