#K8861. K-Diverse Array

    ID: 37347 Type: Default 1000ms 256MiB

K-Diverse Array

K-Diverse Array

You are given an array A of n integers and an integer k. An array is called k-diverse if the difference between its maximum and minimum element is at most k. In other words, if min and max are respectively the minimum and maximum values in the array, then the array is k-diverse if:

\(\text{max}(A) - \text{min}(A) \le k\)

Your task is to determine, for each test case, whether the given array is k-diverse.

inputFormat

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 k, where n is the number of elements in the array.
  • The second line contains n space-separated integers representing the elements of the array.

You need to process each test case independently.

outputFormat

For each test case, print a single line containing YES if the array is k-diverse and NO otherwise.

## sample
3
3 3
1 4 3
4 2
7 12 10 8
5 0
5 5 5 5 5
YES

NO YES

</p>