A gas station too far

There is just one road connecting the n + 1 cities c₀, …, c_(n)
consecutively. You want to go from c₀ to c_(n) stopping at most s times
to fill the tank of the car. There are gas stations at the cities, but
none on the roads. The length of each road is ℓ₀, …, ℓ_(n − 1). Which is
the minimum range for your car? Suppose that you start with a full tank.

Input

Input consists of several cases. Every case begins with n and s, which
are followed by n natural numbers ℓ₀, …, ℓ_(n − 1). Suppose 1 ≤ n ≤ 10⁵,
0 ≤ s ≤ n − 1, and 1 ≤ ℓ_(i) ≤ 10⁴.

Output

For every case, print the minimum range for a car to reach c_(n)
starting from c₀ stopping at most s times to fill the tank.

Hint

Consider a decisional version of this problem.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T10:18:51.759Z

© Jutge.org, 2006–2026.
https://jutge.org
