#C8309. Find Unique Pairs with Sum
Find Unique Pairs with Sum
Find Unique Pairs with Sum
You are given a list of integers and a target sum \(t\). Your task is to find all the unique pairs \((a, b)\) from the list such that \(a+b=t\). Each pair should be sorted in ascending order (i.e., \(a \le b\)) and the final list of pairs must be sorted by the first element.
If there are duplicate numbers in the input, they should be treated as distinct occurrences, but the resulting unique pair should appear only once. If no pairs exist, output an empty list []
.
Note: The sum condition can be written in \(\LaTeX\) as \(a+b=t\).
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains two integers \(n\) and \(t\) separated by a space, where \(n\) is the number of elements in the list and \(t\) is the target sum.
- The second line contains \(n\) integers separated by spaces representing the elements of the list.
outputFormat
Print the list of unique pairs to standard output (stdout) in the following format: the list should be printed as a Python-style list of tuples. Each tuple should be in the form (a, b)
with no extra spaces between the numbers and punctuation, and the overall list should be ordered by the first element of each pair. If no valid pair exists, print []
.
6 7
1 2 3 4 5 6
[(1, 6), (2, 5), (3, 4)]