#K46912. Unique Pairs with Target Sum

    ID: 28082 Type: Default 1000ms 256MiB

Unique Pairs with Target Sum

Unique Pairs with Target Sum

Given an array of integers and a target sum (S), your task is to find all unique pairs ((a, b)) such that (a + b = S) and (a \le b). Each test case consists of a number (N) (the number of elements in the array) and the target sum (S), followed by (N) integers. For each test case, you must identify the pairs, sort them in lexicographical order, and print them on a single line with each pair formatted as ((a, b)). If no such pairs exist, output an empty line.

Note: Output exactly one line per test case, and separate multiple pairs with a single space.

inputFormat

The first line contains an integer (T) representing the number of test cases. For each test case, the first line contains two integers (N) and (S) separated by a space. The next line contains (N) space-separated integers.

outputFormat

For each test case, print one line containing the sorted unique pairs that add up to (S). Each pair should be formatted as ((a, b)) (with a comma and a space between the numbers) and pairs must be separated by a single space. If there are no valid pairs, output an empty line.## sample

1
5 7
1 2 3 4 5
(2, 5) (3, 4)

</p>