#K61152. Minimum Teams Formation

    ID: 31246 Type: Default 1000ms 256MiB

Minimum Teams Formation

Minimum Teams Formation

You are given N employees, each with a certain skill level. Your task is to form teams such that within each team, the difference between the smallest and largest skill levels is at most \(D\) (in \(\LaTeX\) format: \(a_j - a_i \le D\)). The goal is to minimize the total number of teams.

Input: The first line contains two integers \(N\) and \(D\) separated by a space. The second line contains \(N\) integers representing the skill levels of the employees.

Output: Output a single integer — the minimum number of teams required.

Example:

Input:
6 3
1 4 6 8 9 10

Output: 3

</p>

Hint: A greedy strategy works here. First, sort the skill levels, then group consecutive employees as long as the difference between the first and current employee does not exceed \(D\).

inputFormat

The input is given via stdin and it consists of two lines:

  • The first line contains two space-separated integers \(N\) (the number of employees) and \(D\) (the maximum allowed difference in skill levels within a team).
  • The second line contains \(N\) space-separated integers denoting the skill levels of the employees.

outputFormat

The output should be written to stdout and is a single integer representing the minimum number of teams required to group all employees according to the given condition.

## sample
6 3
1 4 6 8 9 10
3