#C14664. Unique Pairs with Target Sum

    ID: 44338 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 identify all the unique pairs \((a, b)\) from the list such that:

\(a+b=T\)

Each pair must be sorted in non-decreasing order (i.e. \(a \leq b\)) and the overall list of pairs must not contain duplicates. When printing the output, each pair should be printed on a new line with the two numbers separated by a single space, and the pairs should be sorted in lexicographical order (first by the first element, then by the second element). If no valid pairs exist, output nothing.

Note: Use the \(\LaTeX\) format for formulas.

inputFormat

The input is read from standard input (stdin) and consists of three parts:

  1. An integer \(n\) on the first line, representing the number of elements in the list.
  2. A line containing \(n\) space‐separated integers.
  3. An integer on the third line representing the target sum \(T\).

outputFormat

Print each unique pair on a separate line in the format "a b", where \(a\) and \(b\) are the elements of the pair in ascending order. The overall list of pairs should be sorted in lexicographical order. If no such pairs exist, output nothing.

## sample
0

5