#C13842. Unique Pair Sum
Unique Pair Sum
Unique Pair Sum
You are given a list of integers and a target value. Your task is to find all unique pairs of numbers from the list such that the sum of the two numbers is equal to the target. Each pair should be output in ascending order (i.e. the smaller number first) and the list of pairs must be sorted in lexicographical order.
Note: A pair consisting of the same number is allowed if the number appears at least twice in the list. Formally, if we denote a pair as \((a, b)\), then we require
[ a \leq b \quad \text{and} \quad a+b = T ]
where \(T\) is the target sum.
Example:
Input: 6 10 5 2 3 7 5 10</p>Output: 2 3 7 5 5
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains a single integer \(n\), the number of elements in the list.
- The second line contains \(n\) space-separated integers representing the elements of the list.
- The third line contains a single integer \(T\) representing the target sum.
outputFormat
Output the result to standard output (stdout) in the following format:
- The first line should be an integer \(m\) indicating the number of unique pairs found.
- The next \(m\) lines should each contain two integers separated by a single space representing a unique pair. Each pair must have the smaller number first.
- If no such pair exists, output 0 on the first line.
6
10 5 2 3 7 5
10
2
3 7
5 5
</p>