#C3812. Find Pairs with Sum
Find Pairs with Sum
Find Pairs with Sum
Given an array of integers and a target integer \(T\), your task is to find all unique pairs of integers \((a, b)\) from the array such that \(a + b = T\). Each pair should be output in the format \((a, b)\) with \(a \le b\). The resulting list of pairs must be sorted in ascending order, first by the first element and then by the second element if necessary.
If no such pairs exist, simply output No pairs found.
Note: Each pair must be unique, i.e. even if multiple instances of the same numbers exist in the array, the pair should appear only once in the output.
Examples:
- Input:
1 2 3 4 5 6
and7
→ Output:[(1, 6), (2, 5), (3, 4)]
- Input:
5 6 7 8
and3
→ Output:No pairs found
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a space-separated list of integers representing the array.
- The second line contains a single integer representing the target sum \(T\).
outputFormat
Output to standard output (stdout) the list of unique pairs in the following format:
- If at least one pair is found, print the list of pairs exactly in Python list format. For example:
[(1, 6), (2, 5), (3, 4)]
- If no such pair exists, print:
No pairs found
1 2 3 4 5 6
7
[(1, 6), (2, 5), (3, 4)]