CF441B.Valera and Fruits

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Valera loves his garden, where nn fruit trees grow.

This year he will enjoy a great harvest! On the ii -th tree bib_{i} fruit grow, they will ripen on a day number aia_{i} . Unfortunately, the fruit on the tree get withered, so they can only be collected on day aia_{i} and day ai+1a_{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 vv 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 nn and vv (1<=n,v<=3000)(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 nn lines contain the description of trees in the garden. The ii -th line contains two space-separated integers aia_{i} and bib_{i} (1<=ai,bi<=3000)(1<=a_{i},b_{i}<=3000) — the day the fruits ripen on the ii -th tree and the number of fruits on the ii -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 33 fruits from the 11 -st tree.
  • On the second day collect 11 fruit from the 22 -nd tree and 22 fruits from the 11 -st tree.
  • On the third day collect the remaining fruits from the 22 -nd tree.

In the second sample, you can only collect 6060 fruits, the remaining fruit will simply wither.

首页