#C1051. Find Pair with Sum
Find Pair with Sum
Find Pair with Sum
You are given an array of integers and a target integer \(k\). Your task is to determine whether there exists a pair of distinct integers in the array such that their sum equals \(k\). If such a pair exists, output the two numbers; otherwise, output None
.
Note: A pair is considered valid if the two integers come from different positions in the array even if they have the same value.
For example, if the input array is [10, 15, 3, 7] and \(k=17\), the output should be 10 7
because \(10+7=17\>.
inputFormat
The input is given in two lines via standard input.
- The first line contains two integers \(n\) and \(k\), where \(n\) represents the number of elements in the array, and \(k\) is the target sum.
- The second line contains \(n\) space-separated integers representing the elements of the array.
It is guaranteed that \(n \geq 0\). In case \(n=0\) or a valid pair cannot be found, the output should be None
.
outputFormat
Output a single line to standard output. If a pair of distinct integers exists whose sum equals \(k\), print the two integers separated by a space (in the order they are found). Otherwise, print None
.
4 17
10 15 3 7
10 7