CF441B.Valera and Fruits
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b__i fruit grow, they will ripen on a day number a__i. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a__i and day a__i + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
瓦列拉热爱他的花园,园中生长着 n 棵果树。
今年他将迎来大丰收!第 i 棵树上结有 bi 个果实,这些果实在第 ai 天成熟。不幸的是,树上的果实会枯萎,因此只能在第 ai 天和第 ai+1 天采摘(在这两天内未采摘的果实将变得无法食用)。
瓦列拉的动作并不快,但也有几个有利条件:他愿意每天都工作;并且每天最多能采摘 v 个果实(这些果实可以来自同一棵树,也可以来自不同的树)。如果瓦列拉采取最优策略,他最终最多能采摘多少果实?
输入格式
The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a__i and b__i (1 ≤ a__i, b__i ≤ 3000) — the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
第一行包含两个以空格分隔的整数 n 和 v(1≤n,v≤3000)—— 分别表示花园中果树的数量,以及瓦莱拉每天能够采集的水果数量。
接下来的 n 行描述花园中的果树。第 i 行包含两个以空格分隔的整数 ai 和 bi(1≤ai,bi≤3000)—— 分别表示第 i 棵果树上的水果成熟日期,以及该树上的水果数量。
输出格式
Print a single integer — the maximum number of fruit that Valera can collect.
输出一个整数——Valera 能收集到的水果最大数量。
输入输出样例
输入#1
2 3 1 5 2 3
输出#1
8
输入#2
5 10 3 20 2 20 1 20 4 20 5 20
输出#2
60
说明/提示
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.
在第一个样例中,为获得最优答案,您应按以下方式操作:
- 第一天从第 1 棵树上采摘 3 个水果。
- 第二天从第 2 棵树上采摘 1 个水果,从第 1 棵树上采摘 2 个水果。
- 第三天采摘第 2 棵树上剩余的全部水果。
在第二个样例中,您只能采摘 60 个水果,其余水果将直接枯萎。
输入解题思路,AI测评打分。不知道怎么写?