#K34077. Find the First Pair That Sums to a Target
Find the First Pair That Sums to a Target
Find the First Pair That Sums to a Target
You are given an array of integers and a target integer s. Your task is to find the first pair of numbers in the array that add up to s. In other words, find two numbers x and y such that
\( x + y = s \)
where the pair (x, y) is the first valid pair encountered in the order they appear in the array. If such a pair exists, output the two numbers separated by a space. Otherwise, output None
.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer n, which denotes the number of elements in the array.
- The second line contains n space-separated integers representing the elements of the array.
- The third line contains an integer s, the target sum.
outputFormat
Print the first pair of integers from the list whose sum equals s. The two integers should be printed in the order they appear in the input separated by a space. If no such pair exists, print None
.## sample
6
1 4 8 7 3 15
8
1 7