#K11236. Pair Sum Problem
Pair Sum Problem
Pair Sum Problem
You are given a list of integers and an integer k. Your task is to determine whether there exists any pair of distinct elements in the list that adds up to k. In other words, check if there exist two different indices i and j such that:
\( a_i + a_j = k \)
The input is provided via stdin and the output should be printed to stdout as either True
or False
(without quotes).
Note:
- If the list has fewer than 2 elements, the answer is
False
. - The list may contain duplicate values or negative numbers.
inputFormat
The input consists of three lines:
- The first line contains an integer n, representing the number of elements in the list.
- The second line contains n space-separated integers.
- The third line contains an integer k, the target sum.
It is guaranteed that n is non-negative. When n equals 0, the second line will be empty.
outputFormat
Output a single line containing either True
if there exists a pair of distinct numbers whose sum is k, or False
otherwise.
4
10 15 3 7
17
True
</p>