#C10034. Find Pair with Given Sum

    ID: 39195 Type: Default 1000ms 256MiB

Find Pair with Given Sum

Find Pair with Given Sum

You are given a list of integers and a target integer k. Your task is to find two distinct elements in the list whose sum equals k. If such a pair exists, print the two numbers in non-decreasing order (i.e., the smaller number first). If there is no such pair, output None.

Note: Each test case is provided via standard input. You need to read the input from stdin and output the result to stdout. The solution must run within the provided time limits.

The logic behind the solution typically involves using a hash set to store the previously seen numbers and checking for the complement (k − current number) using the relation:

\(\text{if } x \in \text{seen and } k-x \text{ is found, then } (\min(x, k-x),\max(x, k-x))\) is the answer.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains a single integer n, representing the number of elements in the list.
  • The second line contains n space-separated integers representing the list.
  • The third line contains a single integer k, the target sum.

outputFormat

Output a single line. If a pair exists, print the two numbers in non-decreasing order separated by a space. Otherwise, output None.

## sample
4
10 15 3 7
17
7 10