Bukazoids
InterviewTime limit1sMemory limit128 MB
Given cell counts and a fixed number of single and double jumps, maximize collected bukazoids and output the lexicographically smallest optimal visit sequence.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Greedy, Array, Implementation
- Solved
- No attempts yet
Problem
A gluttonous robot lives on a strip of cells numbered from to . The robot starts at cell . Every cell other than cell contains some bukazoids, which the robot eats whenever it lands on that cell.
The robot moves only forward and makes exactly two kinds of jumps:
- a single jump moves it to the next cell (distance );
- a double jump moves it over one cell (distance ).
It performs exactly single jumps and double jumps, and these counts satisfy , so after all of its jumps the robot lands exactly on cell . Along the way it collects the bukazoids of every cell it lands on.
Find the maximum total number of bukazoids the robot can collect.
Input
The first line contains three integers (), (), and (), satisfying .
The second line contains integers: the number of bukazoids in cells in order. Each value is an integer between and .
Output
On the first line, print the maximum total number of bukazoids.
On the second line, print the cell numbers the robot visits, starting from cell , that achieve this maximum. If several routes collect the maximum, print the lexicographically smallest such sequence of cell numbers (compare the two sequences position by position; the one with the smaller value at the first position where they differ is smaller).