#K39402. Finding Unique Pairs with a Fixed Sum

    ID: 26412 Type: Default 1000ms 256MiB

Finding Unique Pairs with a Fixed Sum

Finding Unique Pairs with a Fixed Sum

You are given an array of integers and an integer (k). Your task is to find all unique pairs ((a, b)) such that (a + b = k) and (a < b). Each pair should be output exactly once, regardless of duplicate entries in the input array. For example, if the array is [1, 2, 3, 4, 5] and (k = 5), the valid unique pairs are ((1, 4)) and ((2, 3)). The solution must read from standard input (stdin) and write to standard output (stdout).

inputFormat

The input is provided via 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 array.
  3. The third line contains the integer (k), the target sum.

outputFormat

Output all unique pairs with (a < b) such that (a + b = k). Each pair should be printed on a separate line in the format: "a b". The pairs must be printed in increasing order based on the first element, and if there is a tie, based on the second element. If no such pair exists, output nothing.## sample

5
1 2 3 4 5
5
1 4

2 3

</p>