CF441B Valera and Fruits
题目描述
Valera很爱他的花园,因为那里生长着n棵果树。
今年他将迎来一场大丰收!第i棵树上会结出bi个果实,它们将在第ai天全部成熟。不幸的是,这些果子将很快枯萎,因此Valera只能在第ai天和第ai+1天摘下它们。(所有不在指定的两天内摘下的果子,都不可食用)
Valera的动作不是很快,但他也有自己的优势。他已经准备好了,以保证每天都可以工作。一天,Valera最多可以摘下v个果子,这些果子有可能是同一棵树上的,也有可能不是。那么,在合理安排日程表的情况下,Valera最多可以收获多少个果子?
输入格式
第1行包含两个用空格隔开的整数,n和v(1
输出格式
输出一个整数——即Valera所能收获的果子的最大值。
说明/提示
In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect $ 3 $ fruits from the $ 1 $ -st tree.
- On the second day collect $ 1 $ fruit from the $ 2 $ -nd tree and $ 2 $ fruits from the $ 1 $ -st tree.
- On the third day collect the remaining fruits from the $ 2 $ -nd tree.
In the second sample, you can only collect $ 60 $ fruits, the remaining fruit will simply wither.