#C13857. Find Unique Pairs with Given Sum
Find Unique Pairs with Given Sum
Find Unique Pairs with Given Sum
You are given an array of integers and a target integer \(T\). Your task is to find and report all unique pairs \((a, b)\) such that \(a + b = T\). Each pair must satisfy \(a \le b\) (i.e. the pair is in ascending order) and duplicate pairs should be discarded.
Input Format: The first line contains an integer \(N\) which denotes the number of elements in the array. The second line contains \(N\) space-separated integers representing the array elements. The third line contains an integer representing the target sum \(T\).
Output Format: If one or more valid pairs exist, print each unique pair on a new line where the two numbers are separated by a space, and the pairs are sorted in ascending order based on their first then second elements. If no such pair exists, print None
.
inputFormat
The input is read from standard input (stdin) and consists of three lines:
- Line 1: An integer \(N\) indicating the number of elements in the array.
- Line 2: \(N\) space-separated integers representing the array.
- Line 3: An integer \(T\), the target sum.
outputFormat
The output should be printed to standard output (stdout). For each pair found, output a line containing the two integers separated by a space. Pairs must be unique and each pair's two numbers must be in ascending order. If no valid pair exists, output a single line with the text None
.
6
1 2 3 4 5 6
7
1 6
2 5
3 4
</p>