#C10697. Find Pairs With Sum
Find Pairs With Sum
Find Pairs With Sum
Given a list of integers and a target sum, your task is to find all unique pairs whose elements add up exactly to the target. For each pair \((a, b)\), ensure that \(a \le b\). Moreover, each number in the list may be used at most once and the final list of pairs must be sorted in increasing order based on the first element of each pair.
More formally, given an integer list \(L\) and a target \(T\), find all pairs \((a, b)\) such that:
\[ a + b = T, \quad a \le b \]subject to the constraint that every element in \(L\) can only be used once in forming a pair.
inputFormat
The input is given via standard input (stdin) as follows:
- The first line contains an integer \(n\) which represents the number of elements in the list.
- The second line contains \(n\) space-separated integers representing the list \(L\).
- The third line contains an integer \(T\), the target sum.
outputFormat
The output should be written to standard output (stdout) and formatted as follows:
- The first line contains a single integer representing the number of pairs found.
- Each of the following lines contains two space-separated integers \(a\) and \(b\) (with \(a \le b\)) representing a valid pair.
7
1 2 -1 0 2 -2 3
2
2
-1 3
0 2
</p>