random-generator

Aparna recently created a random number generator and now she wants Harsh to check if it works fine. 
She gives Harsh an array containing N numbers generated from this random number generator of hers, and two integers K and P. If the given array contains more than or equal to K numbers in the range X-P to X+P (both inclusive) for any integer X, then the random generator fails.

If for any X the generator fails then ultimately it fails.

Help Harsh in determining whether the random generator works well or not.

Input:
The first line contains T indicating the number of test cases.
Second line contains 3 space separated integers N, K and P. 
The next line contains N integers generated by the random number generator.  

Output:
For each Test Case Print 'YES' if random generator works correctly else print 'NO'.  (Quotes for clarity)

Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 10^5
1 ≤ K ≤ N
|Element of array| ≤ 10^9
0 ≤ P ≤ 10^9

SAMPLE INPUT
1
5 2 2
2 9 6 8 4

SAMPLE OUTPUT
NO

Explanation

Let X be 3 then X-P=1 and X+P=5. The array contains 2 and 4 in the range(1,5) so the generator fails.

Source: hackerearth | Difficulty: MEDIUM
Tags: Sorting

Greedy algorithms


Solutions:
'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
t=eval(input())
while t>0:
	t-=1
	n,k,p=list(map(int,input().split()))
	l=[int(i) for i in input().split()]
	l.sort()
	c=0
	for i in range(n-k+1):
		if l[k+i-1]-l[i]<=2*p:
			c+=1
	if c==0:
		print("YES")
	else:
		print("NO")