#C13362. Find Pair with Given Difference

    ID: 42892 Type: Default 1000ms 256MiB

Find Pair with Given Difference

Find Pair with Given Difference

You are given a sorted array of integers and a positive integer \(t\) (target). Your task is to find a pair of numbers \(a\) and \(b\) from the array such that their difference is exactly \(t\), i.e., \(|a - b| = t\). If such a pair exists, output the two numbers separated by a space. If there is no such pair, output None.

Note: The given array is guaranteed to be sorted in non-decreasing order. You must read the input from standard input (stdin) and write the output to standard output (stdout).

Example:
For the input array: [-10, -5, 0, 5, 10] and target \(t=15\), one valid output is: -10 5, since \(5 - (-10) = 15\).

inputFormat

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

n
a1 a2 a3 ... an
t

Where:

  • n is the number of elements in the sorted array.
  • a1, a2, ..., an are the elements of the sorted array.
  • t is the target difference.

outputFormat

The output should be produced on standard output (stdout):

  • If a pair is found, print the two integers separated by a space, in the order they appear in the array.
  • If no valid pair exists, print None.
## sample
5
-10 -5 0 5 10
15
-10 5