Random Generator

2.9

10 votes
Algorithms, Binary Search, Greedy Algorithms, Medium, Open, Sorting
Problem

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
Time Limit: 1
Memory Limit: 256
Source Limit:
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.

Editor Image

?