Codeforces Round 476 (Div. 2) [Thanks, Telegram!]
D
Single-use Stones
Codeforces
1900
原题
← CE →
翻译中…

A lot of frogs want to cross a river. A river is $w$ units width, but frogs can only jump $l$ units long, where $l \lt w$. Frogs can also jump on lengths shorter than $l$. but can't jump longer. Hopefully, there are some stones in the river to help them.

翻译中…

The stones are located at integer distances from the banks. There are $a_i$ stones at the distance of $i$ units from the bank the frogs are currently at. Each stone can only be used once by one frog, after that it drowns in the water.

翻译中…

What is the maximum number of frogs that can cross the river, given that then can only jump on the stones?

翻译中…

Input

翻译中…

The first line contains two integers $w$ and $l$ ($1 \le l \lt w \le 10^5$) — the width of the river and the maximum length of a frog's jump.

翻译中…

The second line contains $w - 1$ integers $a_1, a_2, \ldots, a_{w-1}$ ($0 \le a_i \le 10^4$), where $a_i$ is the number of stones at the distance $i$ from the bank the frogs are currently at.

翻译中…

Output

翻译中…

Print a single integer — the maximum number of frogs that can cross the river.

翻译中…

Note

翻译中…

In the first sample two frogs can use the different stones at the distance $5$, and one frog can use the stones at the distances $3$ and then $8$.

翻译中…

In the second sample although there are two stones at the distance $5$, that does not help. The three paths are: $0 \to 3 \to 6 \to 9 \to 10$, $0 \to 2 \to 5 \to 8 \to 10$, $0 \to 1 \to 4 \to 7 \to 10$.

翻译中…

样例

Input #1
10 5
0 0 1 0 2 0 0 1 0
Output #1
3
InputCopy OutputCopy
Input #2
10 3
1 1 1 1 2 1 1 1 1
Output #2
3
InputCopy OutputCopy
题目信息
题号
965D
时间限制
1 s
内存限制
256 MB
标签
二分
网络流
贪心
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。