#K57387. Unique Pair Sum Finder

    ID: 30409 Type: Default 1000ms 256MiB

Unique Pair Sum Finder

Unique Pair Sum Finder

You are given a list of integers and a target integer \( k \). Your task is to find all unique pairs \((a, b)\) from the list such that \( a + b = k \) and \( a \le b \). Each pair should appear only once, regardless of the order of the numbers in the input.

Note: Two pairs \((a, b)\) and \((c, d)\) are considered the same if \( a = c \) and \( b = d \). It is guaranteed that the input list may contain duplicate elements, but each unique pair that sums to \( k \) should be returned only one time.

Example:

Input: n = 5, k = 5, list = [1, 2, 3, 4, 5]
Output: 
1 4
2 3

In this example, the pairs \((1,4)\) and \((2,3)\) both sum up to 5.

inputFormat

The input is read from stdin and consists of two lines:

  • The first line contains two integers \( n \) and \( k \), where \( n \) is the number of elements in the list and \( k \) is the target sum.
  • The second line contains \( n \) space-separated integers representing the list.

outputFormat

The output should be written to stdout. For each unique pair \((a, b)\) satisfying \( a + b = k \) and \( a \le b \), print a line with the two numbers separated by a space. The pairs should be output in ascending order based on the first element, and in case of ties, based on the second element. If there are no valid pairs, output nothing.

## sample
5 5
1 2 3 4 5
1 4

2 3

</p>