#K42532. First Pair with Target Sum
First Pair with Target Sum
First Pair with Target Sum
Given a list of integers and a target sum \(s\), find the first pair of integers (in order of appearance) that add up to \(s\). If no such pair exists, output None
.
The pair is determined by scanning the list from left to right. For each number, if there exists a previously seen number that, together with the current number, sums to \(s\), then that pair is the answer. For example, if the list is [1, 4, 8, 7, 3, 15] and \(s = 8\), the answer is 1 7
.
inputFormat
The input consists of two lines:
- The first line contains space-separated integers representing the list. (This line may be empty, in which case the list is considered empty.)
- The second line contains a single integer \(s\), the target sum.
outputFormat
Output the first pair of integers that sum up to \(s\), separated by a space. If no such pair exists, print None
.
1 4 8 7 3 15
8
1 7