A11699 | Single-use Stones
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $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?
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?
输入格式
The first line contains two integers $w$ and $l$ ( $1 \le l < 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.
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.
输出格式
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 \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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted