#C9596. Unique Pair Sum
Unique Pair Sum
Unique Pair Sum
You are given a list of n integers and a target integer \(T\). Your task is to find all unique pairs \((a, b)\) such that \(a+b=T\). For each valid pair, ensure that \(a \leq b\). The list of pairs should then be sorted in ascending order by the first element, and if there is a tie, by the second element.
Input Format: The input is read from standard input (stdin). The first line contains an integer \(n\), the number of elements in the list. The second line contains \(n\) space-separated integers. The third line contains the target integer \(T\).
Output Format: For each unique pair found, output a line with the two integers separated by a single space. If no valid pairs exist, output nothing.
Example:
Input: 6 1 2 3 4 5 6 7</p>Output: 1 6 2 5 3 4
Note: Each pair \((a, b)\) is printed only once even if multiple occurrences exist. In the special case when the same number is used twice (i.e. \(a == b\)), ensure it is printed as a single pair.
inputFormat
Standard input (stdin) will contain:
- An integer \(n\) representing the number of elements.
- A line with \(n\) space-separated integers.
- An integer \(T\) representing the target sum.
outputFormat
Standard output (stdout) should contain the unique pairs that add up to \(T\), one pair per line. Each line must contain two space-separated integers. The order of pairs should be in ascending order by the first element and then the second element. If no such pairs exist, nothing should be printed.
## sample6
1 2 3 4 5 6
7
1 6
2 5
3 4
</p>