#C12473. Find Unique Pairs with Given Sum

    ID: 41904 Type: Default 1000ms 256MiB

Find Unique Pairs with Given Sum

Find Unique Pairs with Given Sum

You are given a list of integers and a target integer k. Your task is to find all unique pairs of integers in the list that add up to k. Each pair should be output as two integers (x and y) where x ≤ y, and the list of pairs must be sorted in lexicographical order.

For example, if the input list is [1, 5, 3, 7, 9, 2, -1, 6] and k = 8, the unique pairs are: (-1, 9), (1, 7), (2, 6), (3, 5).

If there are no pairs that satisfy the condition, output nothing.

Note: The input is read from standard input (stdin) and the output should be written to standard output (stdout).

inputFormat

The first line contains an integer n denoting the number of elements in the list. The second line contains n space-separated integers. The third line contains a single integer k representing the target sum.

For example:

8
1 5 3 7 9 2 -1 6
8

outputFormat

For each unique pair that sums up to k, output a line with the two integers separated by a space. The pairs should be sorted in lexicographical order. If no valid pair exists, print nothing.

For the above sample input, the output should be:

-1 9
1 7
2 6
3 5
## sample
8
1 5 3 7 9 2 -1 6
8
-1 9

1 7 2 6 3 5

</p>