#C10546. Minimum Removals to Satisfy Score Range Threshold

    ID: 39763 Type: Default 1000ms 256MiB

Minimum Removals to Satisfy Score Range Threshold

Minimum Removals to Satisfy Score Range Threshold

Given an array of scores and an integer threshold \(T\), your task is to determine the minimum number of elements that need to be removed so that the difference between the maximum and minimum of the remaining scores is \(\le T\). This problem requires you to process multiple test cases. If the list of scores is empty or a single element is provided, no removal is needed.

Example:

Input:
  n = 5, scores = [1, 5, 8, 2, 10], T = 5
Output:
  2

Explanation: Removing 1 element (for instance, the element 10) makes the range between the minimum and maximum of the remaining scores (\le 5), and it is the minimum removals required.

</p>

inputFormat

The input begins with an integer \(T\) denoting the number of test cases. Each test case consists of three parts:

  1. An integer \(n\) representing the number of scores.
  2. A line with \(n\) space-separated integers denoting the scores. (If \(n = 0\), this line will be empty.)
  3. An integer representing the threshold \(T\) for that test case.

All input is read from standard input (stdin).

outputFormat

For each test case, output a single integer that indicates the minimum number of removals needed such that the difference between the maximum and minimum remaining scores is \(\le\) the given threshold. Each answer should be printed on a new line to standard output (stdout).

## sample
5
5
1 5 8 2 10
5
5
10 20 30 40 50
5
5
1 2 3 4 5
10
0

5
1 2 4 6 8
10
2

4 0 0 0

</p>