AtCoder Beginner Contest 135
翻译中…
Problem Statement
翻译中…
There are $N+1$ towns. The $i$-th town is being attacked by $A_i$ monsters.
翻译中…
We have $N$ heroes. The $i$-th hero can defeat monsters attacking the $i$-th or $(i+1)$-th town, for a total of at most $B_i$ monsters.
翻译中…
What is the maximum total number of monsters the heroes can cooperate to defeat?
翻译中…
Constraints
翻译中…
- All values in input are integers.
$1 \leq N \leq 10^5$$1 \leq A_i \leq 10^9$$1 \leq B_i \leq 10^9$
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
N
A_1 A_2 ... A_{N+1}
B_1 B_2 ... B_N
翻译中…
Output
翻译中…
Print the maximum total number of monsters the heroes can defeat.
翻译中…
样例
Input #1
2
3 5 2
4 5
Output #1
9
If the heroes choose the monsters to defeat as follows, they can defeat nine monsters in total, which is the maximum result.
- The first hero defeats two monsters attacking the first town and two monsters attacking the second town.
- The second hero defeats three monsters attacking the second town and two monsters attacking the third town.
Input #2
3
5 6 3 8
5 100 8
Output #2
22
Input #3
2
100 1 1
1 100
Output #3
3
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。