#K34412. Find Unique Pairs That Sum to Target

    ID: 25304 Type: Default 1000ms 256MiB

Find Unique Pairs That Sum to Target

Find Unique Pairs That Sum to Target

You are given an array of n integers and a target integer k. Your task is to find all unique pairs \( (a, b) \) from the array such that \( a+b=k \). Each pair \( (a, b) \) must be output in non-decreasing order (i.e. \( a \le b \)) and the overall list of pairs must be sorted in ascending order.

If there are no such pairs, output nothing.

Input Constraints:

  • \( 1 \le n \le 10^5 \)
  • Each array element is an integer that can be positive, negative or zero.
  • \( k \) is an integer.

Example:

Input:
5 7
1 2 3 4 5

Output: 2 5 3 4

</p>

inputFormat

The first line of input contains two integers n and k separated by a space, where n is the number of elements in the array and k is the target sum.

The second line contains n integers separated by spaces representing the elements of the array.

outputFormat

Print each unique pair that sums to \( k \) on a separate line, with the two numbers separated by a space. The pairs should be printed in sorted order. If there are no such pairs, print nothing.

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

3 4

</p>