K blocks
Time limit1sMemory limit256 MB
Split the array into exactly K contiguous blocks so the sum of each block's maximum is as small as possible.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Stack, Segment tree
- Solved
- No attempts yet
Problem
You are given a sequence of positive integers. Split the sequence into exactly blocks. A block is a non-empty run of consecutive elements, and every element belongs to exactly one block.
The value of a split is the sum of the largest element of each of the blocks. For the given , find the smallest value a split can have.
Input
The first line contains two integers and ().
The second line contains integers (), the elements of the sequence.
Output
Print one integer, the smallest possible value of a split into blocks.