Problem 01B. Split the Array ≡

Author:Pavel Mesenev   Time limit:5 sec
Input file:Standard input   Memory limit:256 Mb
Output file:Standard output  

Statement

You are given an array of n positive integers a0, a1, …, an − 1 and an integer k. Cut the array into exactly k non-empty contiguous parts: choose k − 1 split points so that every element belongs to exactly one part and the parts appear in the original order.

The cost of a cut is the largest part sum among the k parts. Find the minimum possible cost over all valid cuts.

Input format

The first line contains two integers n and k. The second line contains n space-separated integers a0… an − 1.

Output format

Print one integer — the minimum possible value of the largest part sum.

Constraints

1 ≤ k ≤ n ≤ 2 ⋅ 105

1 ≤ ai ≤ 109

The answer fits into a signed 64-bit integer.

Sample tests

No. Standard input Standard output
1
5 2
7 2 5 10 8
18
2
5 2
1 2 3 4 5
9
3
3 3
1 4 4
4

0.034s 0.009s 18