#C6548. Pair with Difference
Pair with Difference
Pair with Difference
Given an array of integers and a target integer, determine if there exist two distinct indices i and j such that the absolute difference between the corresponding elements equals the target. Formally, you are to check if there exist indices i and j (with i ≠ j) for which
[ |a_i - a_j| = target ]
If such a pair exists, output YES
; otherwise, output NO
.
Note: The input is provided via standard input (stdin) and the output should be written to standard output (stdout).
inputFormat
The first line contains two integers, n and target, where n is the number of elements in the array and target is the required difference. The second line contains n space-separated integers representing the elements of the array.
outputFormat
Output a single line containing YES
if there exists a pair of distinct indices such that the absolute difference of their corresponding elements is equal to target, otherwise output NO
.## sample
5 3
1 5 2 4 6
YES