eolymp
bolt
Try our new interface for solving problems
Problems

K blocks

K blocks

You are given a sequence A of n positive integers. Let’s define “value of a splitting” the sequence to k blocks as a sum of maximums in each of k blocks. For given k find the minimal possible value of splittings.

Input

First line contains two integers n and k (1n105, 1k ≤ min(n, 100)). Next line contains n integers A1, A2, ..., An (1Ai106) - the sequence elements.

Output

Output one number - minimal possible value of a splittings.

Time limit 1 second
Memory limit 64 MiB
Input example #1
5 1
1 2 3 4 5
Output example #1
5
Input example #2
5 2
1 2 3 4 5
Output example #2
6
Source 2014 X Zhautykov Olympiad Almaty, Kazakhstan, January 12-18