#K74212. Check Minimum Difference
Check Minimum Difference
Check Minimum Difference
You are given an integer ( n ), an integer ( d ), and a list of ( n ) integers. Your task is to determine whether there exists a pair of distinct elements ( a_i ) and ( a_j ) such that their absolute difference satisfies ( |a_i - a_j| \le d ).
In other words, check if there exists at least one pair with a small enough difference. If such a pair exists, output "YES", otherwise output "NO".
inputFormat
The input is read from standard input and consists of two lines.
The first line contains two integers ( n ) and ( d ), where ( n ) is the number of elements and ( d ) is the maximum allowed difference.
The second line contains ( n ) space-separated integers representing the elements of the list.
outputFormat
Output a single line to standard output containing the answer: "YES" if there exists a pair of elements such that the absolute difference between them is at most ( d ); otherwise, output "NO".## sample
5 3
1 5 3 9 2
YES