#C615. Unique Pair Sum
Unique Pair Sum
Unique Pair Sum
You are given an array of n
integers and an integer target value \(T\). Your task is to find all unique pairs \((a, b)\) such that
\(a + b = T\)
Each pair \((a, b)\) must be output in sorted order (i.e. the smaller number first) and the list of pairs should be sorted in lexicographical order. A pair is considered unique if no other pair contains the same two numbers, regardless of their order.
If no such pairs exist, output None
.
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer
n
, the number of elements in the array. - The second line contains
n
space-separated integers. - The third line contains an integer
T
representing the target sum.
outputFormat
Print each unique pair that sums up to the target on a new line. For each pair, print the two integers separated by a space. The pairs must be printed in lexicographical order (i.e. sorted by the first element, and then by the second element). If no valid pair exists, print None
.
8
2 7 11 15 -2 2 8 1
9
-2 11
1 8
2 7
</p>