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

#GD0000120. Chia dãy theo hiệu lớn nhất (Partition Array Such That Maximum Difference Is K)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chia dãy theo hiệu lớn nhất (Partition Array Such That Maximum Difference Is K)

Partition Array Such That Maximum Difference Is K

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn nonnegative integers and nonnegative kk, partition all elements into the minimum number of nonempty groups. Each element belongs to one group; original order does not matter. In each group, maximum minus minimum must not exceed kk.

Input

The first line contains n,kn,k. The next line contains nn integers aia_i.

Output

Print the minimum number of valid groups.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 0≤k≤1050\le k\le10^5; 0≤ai≤1050\le a_i\le10^5.
  • Subtask 2 (30 points): 1≤n≤12001\le n\le 1200; 0≤k≤1050\le k\le10^5; 0≤ai≤1050\le a_i\le10^5.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 0≤k≤1050\le k\le10^5; 0≤ai≤1050\le a_i\le10^5.

Examples

Input

5 2
3 6 1 2 5

Output

2

Explanation

Groups {1,2,3}\{1,2,3\} and {5,6}\{5,6\} meet the difference limit, while one group would have difference 6−1=5>26-1=5>2.