#C8735. Check Pair With Difference

    ID: 52750 Type: Default 1000ms 256MiB

Check Pair With Difference

Check Pair With Difference

You are given an array of n integers and an integer k. Your task is to determine whether there exist two distinct elements in the array such that their difference is exactly given by k. Formally, you need to check if there exist indices i and j with i \neq j for which

\( |a_i - a_j| = k \)

If such a pair exists, output YES; otherwise, output NO.

Note that when k = 0, you must check if there is at least one duplicate element in the array.

inputFormat

The input is read from stdin and consists of two lines:

  • The first line contains two integers n and k separated by a space, where n is the number of elements in the array.
  • The second line contains n integers separated by spaces, representing the array elements.

outputFormat

Output a single line to stdout containing either YES if there exists a pair of distinct elements whose difference is exactly k, or NO otherwise.

## sample
5 4
1 5 9 13 17
YES