Codeforces Round 252 (Div. 2)
B
Valera and Fruits
Codeforces
1400
原题
← AC →
翻译中…

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?

翻译中…

Input

翻译中…

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.

翻译中…

Output

翻译中…

Print a single integer — the maximum number of fruit that Valera can collect.

翻译中…

Note

翻译中…

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.

翻译中…

样例

Input #1
2 3
1 5
2 3
Output #1
8
InputCopy OutputCopy
Input #2
5 10
3 20
2 20
1 20
4 20
5 20
Output #2
60
InputCopy OutputCopy
题目信息
题号
441B
时间限制
1 s
内存限制
256 MB
标签
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。