#C14217. Find Pairs with Given Sum
Find Pairs with Given Sum
Find Pairs with Given Sum
You are given a list of integers and a target integer \(target\). Your task is to find all unique pairs \((a, b)\) from the list such that \(a + b = target\) with the constraint \(a \leq b\). Each pair must appear only once in the output even if there are multiple occurrences in the input, and the final list of pairs should be sorted lexicographically.
Note: The pair \((a, b)\) is considered the same as \((b, a)\) and should be reported only once. The result should be printed in the Python list format, for example: [(1, 4), (2, 3)]
.
inputFormat
The input is given via stdin with the following format:
- The first line contains an integer (n), the number of elements in the list.
- The second line contains (n) space-separated integers.
- The third line contains the target integer (target).
outputFormat
Output the list of unique pairs in a single line on stdout in the Python list format. Each pair is represented as (a, b) with no extra spaces except as shown in the examples.
For example: [(1, 4), (2, 3)]## sample
7
1 2 3 4 3 2 5
5
[(1, 4), (2, 3)]