#K4026. Unique Pairs Sum

    ID: 26603 Type: Default 1000ms 256MiB

Unique Pairs Sum

Unique Pairs Sum

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

If no such pair exists, do not output anything.

Note: Each element in the array can be used only once per pair. However, if the same number appears multiple times, it can be used as long as different indices are chosen to form a valid pair, but duplicate pairs should be printed only once.

Examples:

  • For input array [1, 2, 3, 4, 3, 5] and target \(6\), the valid pairs are \((1, 5)\), \((2, 4)\), and \((3, 3)\).
  • For input array [1, 2, 3, 4, 5] and target \(10\), no valid pairs exist.

inputFormat

The input is read from standard input (stdin) and includes three lines:

  1. The first line contains an integer n, representing the number of elements in the array.
  2. The second line contains n space-separated integers, which are the elements of the array.
  3. The third line contains an integer representing the target sum \(T\).

outputFormat

For each valid unique pair, output a line containing the two integers separated by a space. Each pair should be in non-decreasing order and the list of pairs should be sorted in lexicographical order. If no valid pairs exist, output nothing.

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

2 4 3 3

</p>