Board Game
InterviewTime limit1sMemory limit128 MB
Starting on field 1, move forward 1 to 6 fields per step to reach field n while collecting the largest possible sum of visited values.
- Level
Easy3 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
On another rainy day two friends are stuck indoors, so they invent a game.
On a sheet of paper they draw fields. Each field carries two numbers: its index (a distinct integer from to ) and its value (an integer between and ). A pawn starts on field . On every move the player rolls a six-sided die (its faces are numbered through ) and advances the pawn forward by the number rolled. The game ends the instant the pawn lands on field . The player's score is the sum of the values of every field the pawn stood on, counting both the starting field and the final field .
Because the players may pick any rolls they like, one game corresponds to a sequence of forward steps, each between and fields, that starts on field and stops exactly on field . Compute the largest score achievable over all such sequences.
Input
The first line contains an integer (), the number of fields. The second line contains integers (), where is the value of field .
Output
Print one integer: the maximum score that can be obtained on the given board.