#C10782. Maximum Coins Collected

    ID: 40025 Type: Default 1000ms 256MiB

Maximum Coins Collected

Maximum Coins Collected

Problem Description:

You are given an array of coin values and an integer (d) representing the maximum allowed difference between the values of two coins. The process to collect coins is as follows:

1. Sort the array in non-decreasing order.
2. While the array is not empty, remove the first (smallest) coin, increment your count by one, and then update the array to only keep coins that satisfy the condition (|coin - selected| \le d), where (selected) is the coin you just removed.

Your task is to determine the maximum number of coins that can be collected following this process.

Example: For (n = 5), (d = 2) and the coin array ([1, 5, 1, 6, 1]), after sorting we get ([1, 1, 1, 5, 6]). In the first iteration, selecting (1) leaves ([1, 1]) since (|1-1| \le 2); subsequent iterations process the remaining coins, resulting in a total count of 3 coins collected.

inputFormat

Input Format:

The first line contains an integer (T), the number of test cases. Each test case consists of two lines:
- The first line contains two integers (n) and (d), where (n) is the number of coins and (d) is the maximum allowed difference.
- The second line contains (n) space-separated integers representing the coin values.

outputFormat

Output Format:

For each test case, output a single line containing the maximum number of coins collected following the described process.## sample

3
5 2
1 5 1 6 1
4 3
1 4 7 10
6 0
1 2 3 4 5 6
3

2 1

</p>