#P1541. [NOIP 2010 提高组] 乌龟棋
[NOIP 2010 提高组] 乌龟棋
Description
On Xiaoming’s birthday, his father gave him a Turtle Chess set as a gift.
The Turtle Chess board is a row of cells, each with a score (a non-negative integer). Cell is the only starting point, and cell is the end. The player controls a turtle piece to move from the start to the end.
There are crawling cards in Turtle Chess, divided into different types (the cards do not necessarily include all types; see the sample). Each type of card is labeled with one of the numbers , meaning that after using such a card, the turtle moves forward by the corresponding number of cells. In the game, each time the player must choose one crawling card that has not been used before from all cards, and move the turtle forward accordingly. Each card can be used only once.
In the game, the turtle automatically gains the score of the starting cell, and during subsequent moves, whenever it arrives at a cell, it gains that cell’s score. The final score is the sum of the scores of all cells the turtle visits from start to end.
Clearly, different orders of using the crawling cards can lead to different final scores. Xiaoming wants to find an order that maximizes the final score.
Given the score of each board cell and all the crawling cards, can you tell Xiaoming the maximum score he can obtain?
Input Format
Numbers on each line are separated by a single space.
The first line contains two positive integers , the number of board cells and the number of crawling cards.
The second line contains non-negative integers, , where is the score on cell .
The third line contains integers, , which are the numbers on the crawling cards.
The input guarantees that upon reaching the end, exactly all crawling cards have been used.
Output Format
Output one integer, the maximum score Xiaoming can obtain.
9 5
6 10 14 2 8 8 18 5 17
1 3 1 2 1
73
Hint
Each test point: 1 s.
Xiaoming uses the crawling cards in the order , and the score is . Note that since the start is , he automatically gains the score on cell .
Constraints: For of the testdata, . For of the testdata, , and among the types of crawling cards, the count of each type does not exceed . For of the testdata, , and among the types of crawling cards, the count of each type does not exceed ;$0 \le a_i \le 100(1 \le i \le N),1 \le b_i \le 4(1 \le i\le M)$。
Translated by ChatGPT 5
京公网安备 11011102002149号