#K42962. 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 sum. Your task is to find a pair of numbers in the list that add up exactly to the given target sum. If such a pair exists, print the two numbers separated by a space; otherwise, print "None".
If multiple solutions exist, you may output any one of them. Note that the pair must be chosen from the provided list and each element can be used at most once.
The problem can be formulated mathematically as finding two integers \(a\) and \(b\) from an array \(A\) such that:
[ a + b = target ]
For example, given \(A = [2, 7, 11, 15]\) and \(target = 9\), the pair \(2, 7\) is a valid solution.
inputFormat
The input is read from stdin and follows the format below:
T n target a1 a2 a3 ... an ... (this format repeats for T test cases)
Here:
- T: An integer denoting the number of test cases.
- n: The number of elements in the array for the test case.
- target: The target sum we want to achieve.
- a1, a2, ..., an: The list of integers.
outputFormat
For each test case, output the pair of integers (separated by a space) that sum up to the target. If no such pair exists, output None. Each test case's answer should be printed on a new line to stdout.
## sample1
4 9
2 7 11 15
2 7
</p>