#K66822. Unique Pairs with Given Sum
Unique Pairs with Given Sum
Unique Pairs with Given Sum
You are given an array of integers and a target sum \( T \). Your task is to find all unique pairs of numbers \( (a, b) \) from the array such that \( a + b = T \). Each pair must be printed in ascending order (i.e. \( a \le b \)) and the list of pairs must be printed in lexicographical order. No duplicate pairs should be included in the output.
Note: The standard input will first contain an integer \( n \) representing the number of elements in the array, followed by the target sum \( T \), and then \( n \) space-separated integers. The standard output should first print the number of unique pairs, and then each pair on a new line.
For example, if the input is:
6 6 2 3 4 2 1 5
The output should be:
2 1 5 2 4
inputFormat
The first line of input contains two space-separated integers: \( n \) (the number of elements in the array) and \( T \) (the target sum). The second line contains \( n \) space-separated integers representing the array.
Example:
6 6 2 3 4 2 1 5
outputFormat
Output the number of unique pairs that sum up to \( T \) on the first line. Then, for each unique pair, output the two integers separated by a space on a new line. The pairs should be listed in lexicographical (ascending) order.
Example:
2 1 5 2 4## sample
6 6
2 3 4 2 1 5
2
1 5
2 4
</p>