Split the sequence
Time limit2sMemory limit128 MB
Split the sequence into k+1 contiguous parts so the total product score from the cuts is maximal, and print the score with one optimal cut list.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Divide and conquer, Math, Prefix sum
- Solved
- No attempts yet
Problem
Split a sequence of nonnegative integers into nonempty contiguous parts using cuts. Each cut splits one current part into two, and the score gained is the product of the sums of the two new parts. The order of cuts does not change the total score. Find the maximum total score and one valid list of cut positions.
Input
The first line contains and (, ). The second line contains ().
Output
Print the maximum score on the first line. On the second line print cut positions in order. Any optimal answer is accepted.