#C4912. Find Pair with Sum
Find Pair with Sum
Find Pair with Sum
You are given an array of n integers and a target integer. Your task is to determine if there exist two distinct elements in the array whose sum is equal to the target value. If such a pair exists, print the two numbers (in the order they are found by the algorithm). If no such pair exists, output an empty tuple represented by ()
in the output.
Note: If there are multiple answers, printing any one valid pair is acceptable.
The solution must read from standard input and output the result to standard output.
inputFormat
The input consists of three lines:
- The first line contains an integer n, the number of elements in the array.
- The second line contains n space-separated integers representing the array.
- The third line contains the target integer.
For example:
5 2 7 11 15 -2 9
outputFormat
If a pair is found whose sum equals the target, output the two integers separated by a space. If no such pair exists, output ()
.
5
2 7 11 15 -2
9
2 7
</p>