Under construction

Still being built. Things may change

Dao's Race Competition

Interview

Time limit1sMemory limit1024 MB

Summary
Find the fewest tracks to extend by K (each at most once) so the lengths strictly increase, or report -1 if impossible.
Level

Medium4 of 10

Topics
Dynamic programming, Array
Solved
No attempts yet

Problem

Dao is practicing for a race.

Dao prepared NN tracks for a race meet. The track raced ii-th has length AiA_i.

The audience wants the race to be exciting, which means the track lengths should keep getting longer. In other words, the race is exciting when A1<A2<⋯<ANA_1<A_2<\cdots<A_N. To do this, Dao can perform the following operation zero or more times.

  • Choose an index ii with 1≤i≤N1\le i\le N, then increase the length of the ii-th track by KK. That is, change AiA_i to Ai+KA_i+K.
  • For each ii, this operation can be performed at most once.

Determine whether Dao can make the track lengths strictly increasing. If possible, find the minimum number of operations needed.

Input

The first line contains the number of tracks NN and the length KK by which a track can be extended, separated by a space.

The second line contains the integers A1A_1, A2A_2, ⋯\cdots, ANA_N, which give the length of each track, separated by spaces.

Output

If Dao can make the track lengths strictly increasing, print the minimum number of operations needed.

If Dao cannot make the track lengths strictly increasing, print -1.

Constraints

  • 1≤N≤1051\le N\le 10^5
  • 1≤K≤1091\le K\le 10^9
  • 0≤Ai≤1090\le A_i\le 10^9

Examples3

  1. Example 1

    Input
    3 2
    4 3 4
    
    Expected output
    2
    
  2. Example 2

    Input
    3 5
    7 5 5
    
    Expected output
    -1
    
  3. Example 3

    Input
    6 5
    2 4 3 9 5 8
    
    Expected output
    3