Description
Cluster analysis, or also known as clustering, is a task to group a set of objects into one or more groups
such that objects belong to a same group are more similar compared to object in other groups. In this
problem, you are given a set of N positive integers and an integer K. Your task is to compute how
many clusters are there in the given set where two integers belong to a same cluster if their difference
is no larger than K.
For example, let there be a set of N = 7 positive integers: 2, 6, 1, 7, 3, 4, 9, and K = 1.
Based-on the cluster definition of K, we know that:
· 2 and 1 belong to a same cluster (the difference is no more than K = 1),
· 2 and 3 belong to a same cluster,
· 6 and 7 belong to a same cluster,
· 3 and 4 belong to a same cluster.
From these observations, we can conclude that there are 3 clusters in this example: {2, 1, 3, 4}, {6,
7}, and {9}.
Figure 1.
Figure 1 illustrates the clustering result. A line connecting two numbers means that those two
numbers should belong to a same cluster according to the definition.
Input
The first line of input contains an integer T (T ≤ 100) denoting the number of cases. Each case begins
with two integers in a line: N and K (1 ≤ N ≤ 100; 1 ≤ K ≤ 1, 000, 000) denoting the set size and
the clustering parameter respectively. The next line contains N integers Ai (1 ≤ Ai ≤ 1, 000, 000)
representing the set of positive integers. You are guaranteed that all integers in the set are unique
Output
For each case, output ‘Case #X: Y ’, where X is the case number starts from 1 and Y is the number
of cluster for that particular case.
Explanation for 2nd sample case:
The given set is exactly the same as in 1st sample, however, now K = 2. With two additional
observations (compared to 1st sample): 4 and 6 are in the same cluster, 7 and 9 are in the same cluster;
all those integers will be in the same cluster.
Explanation for 3rd sample case:
There are 2 clusters: {1, 4}, and {15, 20, 17}.
Explanation for 4th sample case:
In this sample, all integers will be in their own cluster.