#K4036. Unique Pair Sum Finder
Unique Pair Sum Finder
Unique Pair Sum Finder
You are given an array of integers and a target sum \(T\). Your task is to find all unique pairs \((a, b)\) from the array such that:
\(a + b = T\)
Each pair should be output with the smaller number first and the pairs overall should be sorted in ascending order (first by the first element and then by the second element). Note that each unique pair should only be printed once even if multiple occurrences exist in the input.
Input/Output: The solution should read input from standard input (stdin) and output the results to standard output (stdout).
Example:
Input: 7 2 4 3 5 7 8 -1 7</p>Output: -1 8 2 5 3 4
inputFormat
The input is read from standard input and consists of three parts:
- An integer \(n\) on the first line representing the number of elements in the array.
- A line with \(n\) space-separated integers.
- An integer \(T\) on the next line representing the target sum.
outputFormat
The output should be printed to standard output. For each unique pair \((a, b)\) where \(a + b = T\) (with \(a \le b\)), print a line containing the two numbers separated by a single space. The pairs must be sorted in ascending order by the first element and then by the second. If no valid pair exists, output nothing.
## sample7
2 4 3 5 7 8 -1
7
-1 8
2 5
3 4
</p>