#K44232. Unique Pairs with Target Sum

    ID: 27486 Type: Default 1000ms 256MiB

Unique Pairs with Target Sum

Unique Pairs with Target Sum

Given a list of integers and a target integer \(T\), your task is to find all unique pairs of numbers that add up to \(T\). Each pair is returned in increasing order (smaller number first) and no duplicate pairs are allowed.

Example: For \(nums = [2, 4, 3, 5, 7, 8, 9]\) and \(T = 7\), the unique pairs are \([2, 5]\) and \([3, 4]\).

You should process the input from stdin and output the result to stdout. Each pair must be printed on a new line with the two numbers separated by a space. If no valid pair exists, output nothing.

inputFormat

The first line contains an integer \(N\), representing the number of elements in the list. The second line contains \(N\) space-separated integers indicating the elements of the list \(nums\). The third line contains an integer \(T\), the target sum.

outputFormat

Output all the unique pairs that add up to \(T\), one pair per line. Each pair is formatted as two space-separated integers where the smaller number comes first. The pairs should be sorted in lexicographical order (by their first element, then second element). If no pairs are found, output nothing.

## sample
7
2 4 3 5 7 8 9
7
2 5

3 4

</p>