#K9106. Minimum Age Groups
Minimum Age Groups
Minimum Age Groups
You are given T test cases. For each test case, you are given an integer N (the number of people) and an integer K (the maximum allowed age difference within a group). You are also provided with a list of N integer ages. Your task is to determine the minimum number of groups such that in each group, the difference between the oldest and the youngest person is at most $$K$$.
The problem can be formalized as follows: for each test case, partition the sorted ages into the minimum number of segments so that for each segment $$S$$, if min(S) and max(S) denote the smallest and largest age in $$S$$ respectively, then:
Print the result for each test case on a separate line.
inputFormat
The first line of input contains an integer T, 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 separated by a space.
- The second line contains N space-separated integers representing the ages.
outputFormat
For each test case, print a single line containing one integer – the minimum number of groups required.
## sample2
6 5
2 3 10 7 13 8
5 10
1 12 23 34 45
2
5
</p>