问题 6193 --Bessie看Mooloo

6193: Bessie看Mooloo★★

时间限制: 1 Sec  内存限制: 128 MB
提交: 6  解决: 5
[提交][状态][命题人:]

题目描述

Bessie喜欢看Mooloo的节目。因为Bessie是一头忙碌的奶牛,她已经为下一个N计划好了日程(1≤N≤1e5),她将观看Mooloo的日子。因为Mooloo是一家付费订阅服务公司,她现在需要决定如何将需要支付的金额降至最低。

Mooloo有一个有趣的订阅系统:它的花d+K(1≤K≤1e9)的钱订阅Mooloo 连续d天。她可以随时启动订阅,如果当前订阅过期,您可以根据需要多次启动新订阅。现在给定日程表,请计算出Bessie为完成她的日程安排所需支付的最低金额。


Bessie likes to watch shows on Mooloo. Because Bessie is a busy cow, she has planned a schedule for the next N (1≤N≤105) days that she will watch Mooloo. Because Mooloo is a paid subscription service, she now needs to decide how to minimize the amount of money she needs to pay.

Mooloo has an interesting subscription system: it costs d+K (1≤K≤109) moonies to subscribe to Mooloo for d consecutive days. You can start a subscription at any time, and you can start a new subscription as many times as you desire if your current subscription expires. Given this, figure out the minimum amount of moonies Bessie needs to pay to fulfill her schedule.


输入

第一行包含整数N和K。

第二行包含N个整数,描述Bessie观看Mooloo的日期:1≤d1<d2<⋯<dN≤1e14.


The first line contains integers N and K.

The second line contains N integers describing the days Bessie will watch Mooloo: 1≤d1<d2<⋯<dN≤1014.


输出

一个整数,表示所需支付的最低金额。


样例输入
Copy
2 4
7 9
样例输出
Copy
7

提示

测试样例2:
输入:
2 3
1 10
输出:
8

在测试样例1中,Bessie在第7天时买了连续3天,支付了d+k=3+4=7。
在测试样例2中,Bessie在第1天时买了1天,支付了d+k=1+3=4;在第10天时买了1天,又支付了d+k=1+3=4。

来源

[提交][状态]