#C5058. Target Sum Pairs

    ID: 48665 Type: Default 1000ms 256MiB

Target Sum Pairs

Target Sum Pairs

You are given an array of integers and a target integer \(T\). Your task is to find all unique pairs \((a, b)\) from the array such that \(a + b = T\) and \(a \le b\). The resulting pairs must be output in ascending order (first by the first element then by the second element). If no such pair exists, do not output anything.

Note: Each pair should appear only once even if there are duplicates in the input, and the order of pairs must be sorted.

inputFormat

The input is given via standard input and has the following format:

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

It is guaranteed that \(n \ge 0\) and the integers fit into a 32-bit signed integer.

outputFormat

Output each unique pair on a separate line. Each line should contain two integers separated by a single space (the smaller number first). The pairs must be printed in ascending order. If there is no pair that adds up to \(T\), output nothing.

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

1 3

</p>