Log Shipping Windows
A log shipper on an edge server has buffered n log chunks, numbered 1 to n in the order they
were written. The i-th chunk is a_i bytes long. The central log store only accepts uploads
during scheduled upload windows, and tonight there are D of them.
Chunks must arrive in order, and a chunk cannot be split across windows. So each window uploads one
contiguous run of chunks: the first window sends chunks 1 to j_1, the next sends chunks j_1 + 1
to j_2, and so on. A window may also be left unused. Every window is configured with the same byte
budget B, and the total size of the chunks sent in a single window must not exceed B.
Find the smallest budget B (in bytes) that lets all n chunks be shipped within the D windows.
Input
The first line contains two integers n and D (1 ≤ D ≤ n ≤ 2·10^5) — the number of chunks
and the number of upload windows.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the chunk sizes in
bytes, in shipping order.
Output
Print a single integer: the minimum byte budget B per window such that all chunks can be shipped,
in order, using at most D windows.
Note that the answer can exceed 2^32, so use 64-bit integers.
Notes
In the first example, a budget of 18 works: the first window sends chunks of sizes 7, 2, 5 (14 bytes) and the second sends 10, 8 (18 bytes). No split into two contiguous runs keeps both runs at 17 bytes or less.
In the second example the total is 22 bytes over 3 windows, yet a budget of 9 is not enough: each 9-byte chunk then needs a window to itself, which forces the runs 1 | 9 | 1+1+1 | 9 — four windows. With a budget of 10 the windows send 1+9, 1+1+1 and 9.