PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BF0000043. Người nhảy qua mái nhà (House Man)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Người nhảy qua mái nhà (House Man)

House Man

Source: HDU

Version: Phuoc Hung OJ Extended

Problem Statement

The nn houses have distinct heights and a fixed left-to-right order. Relocate them to distinct integer coordinates, preserving order. Successive houses in increasing height order must be at most DD units apart. Maximize the distance between the shortest and tallest houses, or output -1 if impossible.

Input

First line n,Dn,D; then nn pairwise distinct heights in original order.

Output

Print the greatest possible integer separation, or -1.

Subtasks

  • Subtask 1 (20 points): 2≤n≤122\le n\le12, 1≤D≤1001\le D\le100; 1≤hi≤1091\le h_i\le10^9, all hih_i distinct.
  • Subtask 2 (30 points): 2≤n≤1202\le n\le120, 1≤D≤100001\le D\le10000; 1≤hi≤1091\le h_i\le10^9, all hih_i distinct.
  • Subtask 3 (50 points): 2≤n≤10002\le n\le1000, 1≤D≤1061\le D\le10^6; 1≤hi≤1091\le h_i\le10^9, all hih_i distinct.

Examples

Input

4 4
20 30 10 40

Output

3

Explanation

House 33 is the shortest (height 1010) and house 44 is the tallest (height 4040). The jumping order is 3→1→2→43\to1\to2\to4. Coordinates (0,1,2,5)(0,1,2,5) preserve the input order, satisfy each jump bound D=4D=4, and place the extreme-height houses 33 units apart, which is optimal.