#C2047. Find Pairs with Target Sum

    ID: 45320 Type: Default 1000ms 256MiB

Find Pairs with Target Sum

Find Pairs with Target Sum

Given an array of unique integers and a target sum, your task is to find all pairs of numbers (a) and (b) in the array such that (a + b = \text{target}). Each valid pair should be printed in ascending order (i.e. the smaller number first) and the list of pairs should be sorted in lexicographical order. If no valid pairs exist, output nothing.

Note: Each test case input is read from stdin and the result should be printed to stdout.

inputFormat

The input consists of 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 representing the unique elements of the array.
  3. The third line contains a single integer representing the target sum.

outputFormat

For each pair of numbers (a) and (b) found such that (a + b = \text{target}), output a line containing the two integers separated by a space. The pairs must be printed in sorted order. If no such pairs exist, print nothing.## sample

5
1 2 3 4 5
5
1 4

2 3

</p>