#C5199. Pair with Given Sum
Pair with Given Sum
Pair with Given Sum
Given an array of integers and a target value, determine whether there exists a pair of distinct integers in the array whose sum equals the target value.
This can be formally expressed as: Find two indices \(i\) and \(j\) (with \(i \neq j\)) such that
$$ a_i + a_j = target $$
If such a pair exists, output True
; otherwise, output False
.
inputFormat
The input is given via standard input (stdin) in the following format:
n a1 a2 ... an target
Where:
n
is an integer representing the number of elements in the array.- The second line contains
n
space-separated integers representing the array elements. - The third line contains an integer
target
representing the target sum.
outputFormat
Output a single line to standard output (stdout) containing either True
or False
depending on whether such a pair exists in the array.
4
2 7 11 15
9
True