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