All problems

Problem 882

Divide Chocolate

Hard · 30 pts · Array, Binary Search

Problem

A chocolate bar is a row of chunks, each with a sweetness value. Make K cuts to split it into K + 1 pieces of consecutive chunks; you keep the piece with the smallest total sweetness and give the others away. Maximise the sweetness of your piece. For a candidate value X, cut greedily from the left whenever the current piece reaches X; if that yields at least K + 1 pieces, X is achievable. Binary search on X.

Input

The first line contains N and K. The second line contains the N sweetness values.

Output

Print the maximum total sweetness you can get.

Constraints

0 <= K < N <= 10^4; 1 <= sweetness <= 10^5

Example input

9 5
1 2 3 4 5 6 7 8 9

Example output

6

Explanation

For 1 2 3 4 5 6 7 8 9 with K = 5, the pieces 1 2 3 / 4 5 / 6 / 7 / 8 / 9 have sums 6, 9, 6, 7, 8 and 9. The smallest is 6, and no cut does better.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Earliest Possible Day of Full Bloom Next: Kth Smallest Prime Fraction