#K36112. Unique Sum Pairs Finder
Unique Sum Pairs Finder
Unique Sum Pairs Finder
Your task is to find all unique pairs of numbers from a given list that sum up to a specified target. For a pair (a, b), it is considered the same as (b, a); thus, only one occurrence should be included in the result.
Formally, given a list of integers \(L\) and a list of target sums \(T\), find, for each target \(t \in T\), all unique pairs \((a,b)\) with \(a \neq b\) (taken from distinct indices in \(L\)) such that \(a + b = t\). If no such pair exists for a target, output an empty list for that target.
inputFormat
The input is given from stdin as follows:
- The first line contains space-separated integers representing the list of numbers.
- The second line contains space-separated integers representing the target sums.
outputFormat
Print to stdout a dictionary in the following format: each key is a target sum, and its corresponding value is a list of unique pairs that add up to that target sum. Each pair is displayed in the form (a, b)
, and pairs should not be mirrored duplicates. The output should exactly follow the format shown in the examples.
For example:
{5: [(1, 4), (2, 3)], 7: [(1, 6), (2, 5), (3, 4)], 9: [(3, 6), (4, 5)]}## sample
1 2 3 4 5 6
5 7 9
{5: [(1, 4), (2, 3)], 7: [(1, 6), (2, 5), (3, 4)], 9: [(3, 6), (4, 5)]}