#x1027. CF724E Goods transportation
CF724E Goods transportation
Goods transportation
题面翻译
小明升任了 CF 国的大总管,他管辖的 个城市,编号为 。每个城市生产了 个货物,限制最多可以卖掉 个货物。对于每两个城市 ,如果 ,则可以最多从 运送 个货物到 。注意不能反向运送,却可以在多个城市之间送来送去。现在小明想知道,经过运输后,最多能卖掉多少个货物。
感谢@larryzhong 提供的翻译
题目描述
There are cities located along the one-way road. Cities are numbered from to in the direction of the road.
The -th city had produced units of goods. No more than units of goods can be sold in the -th city.
For each pair of cities and such that 1<=i<j<=n you can no more than once transport no more than units of goods from the city to the city . Note that goods can only be transported from a city with a lesser index to the city with a larger index. You can transport goods between cities in any order.
Determine the maximum number of produced goods that can be sold in total in all the cities after a sequence of transportations.
输入格式
The first line of the input contains two integers and ( , ) — the number of cities and the maximum amount of goods for a single transportation.
The second line contains integers ( ) — the number of units of goods that were produced in each city.
The third line of input contains integers ( ) — the number of units of goods that can be sold in each city.
输出格式
Print the maximum total number of produced goods that can be sold in all cities after a sequence of transportations.
样例 #1
样例输入 #1
3 0
1 2 3
3 2 1
样例输出 #1
4
样例 #2
样例输入 #2
5 1
7 4 2 1 0
1 2 3 4 5
样例输出 #2
12
样例 #3
样例输入 #3
4 3
13 10 7 4
4 7 10 13
样例输出 #3
34
相关
在下列比赛中: