#K45417. Pair with Difference K
Pair with Difference K
Pair with Difference K
You are given an array of n integers and an integer K. Your task is to determine whether there exist two indices i and j with i < j such that the absolute difference between the corresponding elements is exactly K. Formally, you need to check if there exists a pair (i, j) such that
$\lvert a_i - a_j \rvert = K$
If such a pair exists output YES
, otherwise output NO
.
inputFormat
The input is given from stdin and consists of two lines. The first line contains two integers n
and K
, where n
is the length of the array. The second line contains n
space-separated integers representing the elements of the array.
Constraints: It is guaranteed that the input values fit within the range of common programming language integer types.
outputFormat
Print a single line to stdout containing either YES
if there exists a pair of indices i < j for which the absolute difference is exactly K, or NO
otherwise.
5 2
1 5 3 4 2
YES