#C6458. Unique Pair Sum Finder
Unique Pair Sum Finder
Unique Pair Sum Finder
Given an array of integers and a target integer \(T\), your task is to find all unique pairs \((a, b)\) from the array such that \(a+b=T\). For each valid pair, ensure that \(a \leq b\). The final list of pairs should be sorted in lexicographical order, meaning that pairs are first compared by the first element and then by the second element.
Note: A pair \((a, b)\) is considered the same as \((b, a)\); duplicates are not allowed. If no valid pair exists, the program should produce no output.
Example: For the array [1, 2, 3, 4, 5] and target 5, the unique pairs are \((1, 4)\) and \((2, 3)\).
inputFormat
The input is read from stdin and consists of three lines:
- An integer \(n\) representing the number of elements in the array.
- \(n\) space-separated integers representing the array elements.
- An integer representing the target sum \(T\).
outputFormat
The output is written to stdout. For each test case, print each unique pair on a separate line in the format a b
(without parentheses). The pairs should be printed in lexicographical order. If there are no valid pairs, output nothing.
5
1 2 3 4 5
5
1 4
2 3
</p>