#K52277. Pair with Given Sum and Difference
Pair with Given Sum and Difference
Pair with Given Sum and Difference
You are given an array of integers and two integers x and y. Your task is to determine if there exists a pair of numbers a and b in the array such that:
\(a + b = y\) and \(a - b = x\).
This is equivalent to checking whether both \(a = \frac{y+x}{2}\) and \(b = \frac{y-x}{2}\) are integers. In the case where a and b are distinct, both must appear in the array. If a and b are equal (which can happen when x = 0), then the number must appear at least twice in the array.
Output True
if such a pair exists and False
otherwise.
inputFormat
The input is given via standard input in the following format:
- An integer
n
representing the number of elements in the array. - A line with
n
space-separated integers. - A line with two space-separated integers
x
andy
, wherex
is the required difference andy
is the required sum.
outputFormat
Output a single line containing either True
or False
(without quotes) to indicate whether such a pair exists.
5
1 5 3 4 2
2 5
True
</p>