#C2084. Find Unique Pairs with Given Sum
Find Unique Pairs with Given Sum
Find Unique Pairs with Given Sum
You are given a list of integers and a target sum \( T \). Your task is to find all unique pairs \((a, b)\) such that \(a + b = T\). Each pair should be output only once and the pairs must be sorted in ascending order first by the first element and then by the second element.
Note: A pair \((a, b)\) is considered the same as \((b, a)\); hence, only one of them should be reported. In the case that there are no pairs with the given sum, output -1
.
Input/Output Format: Read input from stdin
and write output to stdout
. The input consists of two lines. The first line contains two integers \(n\) and \(T\), where \(n\) is the number of elements. The second line contains \(n\) space-separated integers. For output, if at least one valid pair exists, print each pair in a new line with the two numbers separated by a space. If no pair exists, print -1
.
Example:
Input: 5 6 1 2 3 4 3</p>Output: 2 4 3 3
inputFormat
The first line of input contains two integers \(n\) (the number of elements) and \(T\) (the target sum). The second line contains \(n\) space-separated integers representing the list.
Example:
5 6 1 2 3 4 3
outputFormat
If there exists at least one pair, for each unique pair output a line containing the two integers separated by a space, ordered in ascending order. If there is no valid pair, output -1
.
Example Output:
2 4 3 3## sample
5 6
1 2 3 4 3
2 4
3 3
</p>