#K45822. Pair with Given Difference

    ID: 27839 Type: Default 1000ms 256MiB

Pair with Given Difference

Pair with Given Difference

You are given a list of unique integers and a target integer \(k\). Your task is to determine if there exists a pair of numbers in the list such that their difference is exactly \(k\). In other words, find two indices \(i\) and \(j\) (with \(i \neq j\)) for which \(|a_i - a_j| = k\). Note that the order of the numbers does not matter.

For example, if the list is [5, 20, 3, 2, 50, 80] and \(k = 78\), the answer is YES because \(80 - 2 = 78\). Otherwise, if no such pair exists, output NO.

inputFormat

The input is given via standard input (stdin) in the following format:

n
a1 a2 a3 ... an
k

where:

  • \(n\) is the number of elements in the list.
  • The second line consists of \(n\) space-separated integers representing the elements of the list.
  • The third line contains a single integer \(k\), the target difference.

outputFormat

Output a single line via standard output (stdout) containing either YES if there exists any pair of numbers in the list with a difference of exactly \(k\), or NO if no such pair exists.

## sample
6
5 20 3 2 50 80
78
YES