Question 2 / 2 (Amazon Campus(9): MM-Chess)
There're four types of cards in the game and the total number is M. Each type of card are labeled one integer number in [1,4]. After using a card with number x on it, the chess will move x steps forward. Each time, player will choose one unused card to move the chess forward, and each card can only be used once. In the game, the chess gains the score at the starting point automatically. When the chess arrives at a new grid, it also gets the score on that point. The goal of the game is to get the most score.
Input:
The first line contains two integers N (the size of board) and M (the number of the cards).
The second line contains N integers, meaning the scores on the the board (the i-th integer corresponds to the score on the i-th grid).
The third line contains M integers, meaning the numbers on the M cards.
The sum of the number of M cards equals to N-1.
You can assume that 1 <= N <= 350, 1 <= M <= 120, and that the number of cards are less than 40 for each kind.
There is an interesting game called MM-Chess. The size of the board is 1*N, every grid has a score (non-negative). The first grid is the start and the Nth grid is the end. The game requires players to control the chess starting from the starting point to the end.
There're four types of cards in the game and the total number is M. Each type of card are labeled one integer number in [1,4]. After using a card with number x on it, the chess will move x steps forward. Each time, player will choose one unused card to move the chess forward, and each card can only be used once. In the game, the chess gains the score at the starting point automatically. When the chess arrives at a new grid, it also gets the score on that point. The goal of the game is to get the most score.
Input:
The first line contains two integers N (the size of board) and M (the number of the cards).
The second line contains N integers, meaning the scores on the the board (the i-th integer corresponds to the score on the i-th grid).
The third line contains M integers, meaning the numbers on the M cards.
The sum of the number of M cards equals to N-1.
You can assume that 1 <= N <= 350, 1 <= M <= 120, and that the number of cards are less than 40 for each kind.