Disposable Stones
Many frogs are eager to cross a river. The river is w units wide, but each frog can jump a maximum distance of l units, where l < w. Luckily, there are stones scattered across the river that can assist them in reaching the other side.
These stones are positioned at integer distances from the starting bank. At a distance i from the starting bank, there are a[i]
stones available. Each stone can support only one frog before it sinks. Determine the maximum number of frogs that can successfully cross the river using these stones.
Input
The first line contains two integers w and l (1 ≤ l < w ≤ 10^5
) – representing the width of the river and the maximum distance a frog can jump.
The second line provides w-1 integers a[1]
, a[2]
... a[(w-1)]
(0 ≤ a[i]
≤ 10^4
) – indicating the number of stones available at each respective distance.
Output
Print a single integer – the maximum number of frogs that can reach the opposite bank.