Under construction

Still being built. Things may change

Watching Mooloo

Interview

Time limit1sMemory limit1024 MB

Summary
Given N watch days, find the minimum total cost of subscriptions where a subscription of length d costs d plus K and must cover every watch day.
Level

Medium5 of 10

Topics
Dynamic programming, Intervals, Greedy
Solved
No attempts yet

Problem

Bessie likes to watch shows on Mooloo. Because Bessie is a busy cow, she has planned a schedule for the next NN (1≤N≤1051 \leq N \leq 10^5) days that she will watch Mooloo. Because Mooloo is a paid subscription service, she needs to decide how to minimize the amount of money she pays.

Mooloo has an interesting subscription system: it costs d+Kd + K (1≤K≤1091 \le K \le 10^9) moonies to subscribe to Mooloo for dd consecutive days. You can start a subscription at any time, and you can start a new subscription as many times as you want once your current subscription expires. Figure out the minimum amount of moonies Bessie needs to pay to fulfill her schedule.

Input

The first line contains integers NN and KK.

The second line contains NN integers describing the days Bessie will watch Mooloo: 1≤d1<d2<⋯<dN≤10141\le d_1<d_2<\dots<d_N\le 10^{14}.

Output

Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).

Examples2

  1. Example 1

    Input
    2 4
    7 9
    
    Expected output
    7
    
  2. Example 2

    Input
    2 3
    1 10
    
    Expected output
    8