#C12249. Find Unique Pairs Summing to Target
Find Unique Pairs Summing to Target
Find Unique Pairs Summing to Target
You are given a list of integers and a target integer \(T\). Your task is to find all the unique pairs \((a, b)\) from the list such that
\(a + b = T\)
Each pair must satisfy \(a \leq b\) and the list of pairs should be sorted in ascending order first by \(a\) then by \(b\). If no such pair exists, output nothing.
Input Format:
- The first line contains a single 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, output a line with the two integers separated by a space. The pairs must be printed in ascending order.
inputFormat
The input is read from standard input (stdin) and consists of three lines:
- The first line contains a single integer \(n\) indicating the number of elements.
- The second line contains \(n\) space-separated integers.
- The third line contains the target integer \(T\).
outputFormat
For each unique pair that sums to \(T\), output a line with the two integers (with the smaller one first) separated by a space. If there are multiple pairs, they should be printed in ascending order (first by the first element, then by the second). If no such pairs exist, do not output anything.
## sample5
1 2 3 4 5
5
1 4
2 3
</p>