#K38712. Maximum Number of Teams

    ID: 26260 Type: Default 1000ms 256MiB

Maximum Number of Teams

Maximum Number of Teams

You are given t test cases. For each test case, you are given an integer n denoting the number of students and an integer k representing the maximum allowed difference in skill levels in a team. You are also given a list of n integers representing the skill levels of the students. Your task is to form teams such that in each team, the difference between the minimum and maximum skill levels is at most \(k\). Each student can belong to exactly one team. You need to determine the maximum number of teams that can be formed for each test case.

Note: To maximize the number of teams, you can adopt a greedy strategy by sorting the skill levels and then grouping consecutive students together as long as the condition \(\text{skill}_{j} - \text{skill}_{i} \leq k\) is satisfied.

inputFormat

The first line contains an integer t denoting the number of test cases. Each test case is described as follows:

  • The first line of each test case contains two integers n and k, where n is the number of students and k is the maximum allowed difference in skill levels for a team.
  • The second line contains n space-separated integers representing the skill levels of the students.

Please read the input from standard input (stdin).

outputFormat

For each test case, output a single integer on a separate line, representing the maximum number of teams that can be formed.

Please write the output to standard output (stdout).

## sample
1
5 3
1 3 6 7 9
2

</p>