The game consist of two sequences of integers A of length N and B of length M, and it will last for exactly M turns.
In the i-th turn, the corresponding player should select an interval (continuous subsegment) of sequence A of length Bi that is strictly inside the interval selected in previous turn, i.e. if the interval in previous turn was [l,r] then if the interval in current turn is [u,v] then it should satisfy l < u ≤ v < r, except in the first turn where the player can select any interval of length B1.
For the Odd turns we added the sum of all number in range [L,R]( Start with 1 turn) for even turn we subtract all numbers in range [L,R].
What will be the maximum score ? If both player play optimally.
For Example:
A=3 7 5 4 9 6 1 3
B= 6 3 1
- chooses the interval [1, 6] (i.e. (3, 7, 5, 4, 9, 6)). The score now is 34 points.
- In the next turn, chooses the interval [3, 5] (i.e. (5, 4, 9)). The score now is 34 - 18 = 16 points.
- In the next turn, chooses the interval [4, 4] (i.e. (4)). So finally score of the game is 16 + 4 =20.
This is the score of the game when both player play optimally. How to determine the optimal score ?