#C13230. Find Pairs with a Given Sum

    ID: 42746 Type: Default 1000ms 256MiB

Find Pairs with a Given Sum

Find Pairs with a Given Sum

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

If no such pairs exist, output nothing.

Note: Each input case is read from standard input and the output should be written to standard output. The input format is designed so that the first value is the number of elements \(n\), followed by \(n\) integers representing the array, and finally the target sum \(T\).

inputFormat

The input is read from standard input and consists of three lines:

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

outputFormat

Output each unique pair in a separate line. For each valid pair, output two space-separated integers in non-descending order. The pairs themselves must be printed in non-descending lexicographical order. If no valid pair exists, output nothing.

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

2 7 4 5

</p>