#C13130. Finding Unique Pairs with a Given Sum
Finding Unique Pairs with a Given Sum
Finding Unique Pairs with a Given Sum
You are given an array of n integers and an integer target sum \(T\). Your task is to find all unique pairs \((a, b)\) in the array such that \(a+b=T\). Each pair should be output in ascending order, that is, with the smaller number first, and the final list of pairs must be sorted in increasing order by the first element and then by the second element.
If no such pair exists, output None
.
Note: Each pair is considered unique if the combination of numbers is unique, regardless of their positions in the array.
inputFormat
The input is read from standard input and consists of three parts:
- An integer \(n\), representing the number of elements in the array.
- A line with \(n\) space-separated integers.
- An integer \(T\) representing the target sum.
outputFormat
The output should be printed to standard output. For each unique pair \((a, b)\) that satisfies \(a+b=T\), print a separate line in the format:
a b
The pairs must be sorted in ascending order (first by \(a\) then by \(b\)). If no valid pair is found, print None
.
5
1 2 3 4 5
5
1 4
2 3
</p>