#C12098. Find Pair with Target Sum
Find Pair with Target Sum
Find Pair with Target Sum
You are given a list of integers and a target integer. Your task is to find two distinct integers in the list whose sum is exactly equal to the target. If such a pair exists, output the two numbers separated by a single space; otherwise, print None
.
Note: If there are multiple possible pairs, output the pair found first using a left-to-right scanning approach. The input is given via standard input and output via standard output.
The problem can be formally described by the formula:
Find numbers \(a, b\) from list \(L\) such that \(a + b = T\), where \(T\) is the target.
inputFormat
The input consists of three lines:
- The first line contains an integer \(n\), representing 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 representing the target sum \(T\).
outputFormat
If there exists a pair of distinct numbers that add up to the target sum, output the two numbers separated by a space. If no such pair exists, output None
.
4
2 7 11 15
9
2 7
</p>