CF965D.Single-use Stones
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
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?
许多青蛙想要过河。河宽为 w 个单位,但青蛙每次最多只能跳跃 l 个单位,其中 l<w。青蛙也可以跳比 l 更短的距离,但不能跳得更远。幸运的是,河中有一些石头可以帮助它们。
这些石头位于距离两岸整数单位的位置上。在距离青蛙当前所在岸边 i 个单位的位置上有 ai 块石头。每块石头最多只能被一只青蛙使用一次,之后便会沉入水中。
在青蛙只能借助石头跳跃的前提下,最多有多少只青蛙能够成功过河?
输入格式
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.
第一行包含两个整数 w 和 l(1≤l<w≤105)——分别表示河流的宽度和青蛙单次跳跃的最大长度。
第二行包含 w−1 个整数 a1,a2,…,aw−1(0≤ai≤104),其中 ai 表示距离青蛙当前所在河岸为 i 的位置处的石头数量。
输出格式
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.
在第一个样例中,两只青蛙可以分别使用相距为 5 的不同石头,一只青蛙可以依次使用相距为 3 和 8 的石头。
在第二个样例中,尽管存在两块相距为 5 的石头,但这并无帮助。三条路径分别为:0→3→6→9→10,0→2→5→8→10,0→1→4→7→10。
输入解题思路,AI测评打分。不知道怎么写?