#K78032. Find Pair with Given Sum
Find Pair with Given Sum
Find Pair with Given Sum
You are given a list of n integers and a target integer T. Your task is to find two distinct numbers from the list that add up to T. If such a pair exists, output the two numbers in the order you encountered them during your search; otherwise, output -1.
Note: The answer is not unique. As soon as a valid pair is found, output that pair. Use the algorithm with expected linear time complexity.
The mathematical formulation of the problem can be expressed as follows:
Find a and b from the set of numbers such that:
\[ a + b = T, \quad a \neq b \]If no such pair exists, output -1.
inputFormat
The input is given via standard input and consists of two lines:
- The first line contains two integers
n
andT
, wheren
is the number of elements in the list andT
is the target sum. - The second line contains
n
space-separated integers representing the list.
outputFormat
If a valid pair is found, print the two integers separated by a space. Otherwise, print -1.
## sample4 9
2 7 11 15
2 7
</p>