#K51442. Pair Sum Problem
Pair Sum Problem
Pair Sum Problem
You are given a list of integers and a target sum T. Your task is to determine whether there exist two distinct elements in the list whose sum is equal to T. Formally, given a list of integers \(a_1, a_2, \ldots, a_n\) and an integer target \(T\), check if there exist two indices \(i\) and \(j\) (with \(i \neq j\)) such that:
\(a_i + a_j = T\)
If such a pair exists, output True
; otherwise, output False
.
inputFormat
The input is read from standard input and has the following format:
- An integer \(n\) representing the number of elements in the list.
- A line containing \(n\) space-separated integers representing the elements of the list. If \(n = 0\), this line will be empty.
- An integer \(T\) which is the target sum.
outputFormat
Output a single line to standard output, which is either True
or False
, indicating whether there exists a pair of distinct numbers in the list that sum up to \(T\).
4
2 7 11 15
9
True