#K59342. Tree Height Difference

    ID: 30843 Type: Default 1000ms 256MiB

Tree Height Difference

Tree Height Difference

In this problem, you are given a forest with n trees, where each tree has an integer height. You are also provided with an integer (k). Your task is to determine whether there exists a pair of distinct trees such that the absolute difference between their heights is exactly (k).

Formally, given a list (H = [h_1, h_2, \dots, h_n]) and an integer (k), check if there exist indices (i, j) (with (i \neq j)) such that (|h_i - h_j| = k). If such a pair exists, output Yes; otherwise, output No.

inputFormat

The input is given via standard input and consists of two lines.

The first line contains two integers (n) and (k) where (n) is the number of trees and (k) is the desired height difference.

The second line contains (n) space-separated integers representing the heights of the trees.

outputFormat

Output a single line containing either Yes if there exists a pair of trees with an absolute height difference equal to (k), or No otherwise. The output should be printed to standard output.## sample

5 3
1 5 3 8 6
Yes