#C4419. Find Pair with Given Absolute Difference

    ID: 47955 Type: Default 1000ms 256MiB

Find Pair with Given Absolute Difference

Find Pair with Given Absolute Difference

You are given an array of integers and a number k. Your task is to determine whether there exists two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is exactly k. In mathematical terms, you need to check if there exist indices i and j (with i ≠ j) such that:

$|nums[i]-nums[j]| = k$

If such a pair exists, output True; otherwise, output False.

Note: When k = 0, a valid pair means the same number appears at least twice in the array.

inputFormat

The input is given via standard input (stdin) and consists of two lines:

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

If n is 0, the array is considered empty.

outputFormat

Output a single line to the standard output (stdout):

True if there exists at least one pair meeting the condition; otherwise, False.

## sample
7 2
1 7 5 9 2 12 3
True