#C7586. Find Unique Pairs Summing to Target
Find Unique Pairs Summing to Target
Find Unique Pairs Summing to Target
Given a list of integers and a target value \(T\), find all unique pairs \((a, b)\) such that \(a + b = T\). Each pair must be in non-decreasing order (i.e. \(a \le b\)) and the final list of pairs should be sorted in ascending order first by \(a\) and then by \(b\) if necessary.
If there are no such pairs, output an empty list: []
.
inputFormat
The input is provided via stdin in the following format:
- The first line contains an integer \(n\), representing the number of elements in the list.
- The second line contains \(n\) space-separated integers.
- The third line contains an integer \(T\), the target sum.
outputFormat
Output via stdout a single line containing the list of unique pairs in the format: [(a1, b1), (a2, b2), ...]
. If no valid pairs exist, output []
.
5
1 2 3 4 5
5
[(1, 4), (2, 3)]