#C11848. Find the First Sum Pair

    ID: 41209 Type: Default 1000ms 256MiB

Find the First Sum Pair

Find the First Sum Pair

Given an array of integers and a target sum \(T\), your task is to find the first pair of numbers in the array (when traversing from left to right) whose sum is equal to \(T\). If such a pair exists, output the pair in the order they appear in the array; if no such pair exists, output [].

Note:

  • The array may contain negative numbers and duplicates.
  • If a number can be paired with itself (i.e. if it appears at least twice and \(2 \times a = T\)), then output that pair as soon as the condition is met.

The formula for the target is given by:

\(a + b = T\)

inputFormat

The input is given via standard input (stdin) and consists of three parts:

  1. An integer \(n\) representing the number of elements in the array.
  2. A line with \(n\) space-separated integers representing the array elements.
  3. An integer representing the target sum \(T\).

Example:

6
1 4 8 7 3 15
8

outputFormat

The output should be printed to standard output (stdout). If a valid pair exists, print the two numbers separated by a single space on one line. If no such pair exists, print [].

Example Output:

1 7
## sample
6
1 4 8 7 3 15
8
1 7