CF965D.Single-use Stones
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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<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 ai 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?
输入格式
The first line contains two integers w and l ( 1≤l<w≤105 ) — the width of the river and the maximum length of a frog's jump.
The second line contains w−1 integers a1,a2,…,aw−1 ( 0≤ai≤104 ), where ai is the number of stones at the distance i from the bank the frogs are currently at.
输出格式
Print a single integer — the maximum number of frogs that can cross the river.
输入输出样例
输入#1
10 5 0 0 1 0 2 0 0 1 0
输出#1
3
输入#2
10 3 1 1 1 1 2 1 1 1 1
输出#2
3
说明/提示
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→3→6→9→10 , 0→2→5→8→10 , 0→1→4→7→10 .