K blocks

Split the array into exactly K contiguous blocks so the sum of each block's maximum is as small as possible.

Medium7Dynamic programmingStackSegment treeNo attempts yetTime limit1sMemory limit256 MB

Problem

You are given a sequence AA of NN positive integers. Split the sequence into exactly KK 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 KK blocks. For the given KK, find the smallest value a split can have.

Input

The first line contains two integers NN and KK (1KN20001 \le K \le N \le 2000).

The second line contains NN integers A1,A2,,ANA_1, A_2, \ldots, A_N (1Ai1061 \le A_i \le 10^6), the elements of the sequence.

Output

Print one integer, the smallest possible value of a split into KK blocks.