#C12715. Unique Pairs with Target Sum
Unique Pairs with Target Sum
Unique Pairs with Target Sum
Given an array of integers and a target integer \(T\), find all unique pairs \((a, b)\) such that \(a + b = T\). Each pair should be output exactly once, and within each pair, the numbers must be in non-decreasing order (i.e. \(a \leq b\)). The collection of pairs must also be sorted: first by the first element and then by the second element. If no such pair exists, output nothing.
Example:
Input: 6 1 2 3 4 5 6 7</p>Output: 1 6 2 5 3 4
The input is provided via standard input and the output should be printed to standard output.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer \(n\) representing the number of elements in the array.
- The second line contains \(n\) space-separated integers, the elements of the array. If \(n = 0\), this line will be empty.
- The third line contains the target integer \(T\).
outputFormat
Output all unique pairs \((a, b)\) such that \(a + b = T\). Each pair should be printed on its own line in the format "a b". The pairs must be ordered in non-decreasing order of the first element and, for the same first elements, by the second element. If no valid pair exists, output nothing.
## sample6
1 2 3 4 5 6
7
1 6
2 5
3 4
</p>