#K80592. Find Pair with Given Sum
Find Pair with Given Sum
Find Pair with Given Sum
You are given an array of integers and a target integer \(T\). Your task is to determine if there exist two different elements in the array whose sum is exactly \(T\). If such a pair exists, output YES a b
where a
and b
are the two numbers (in the order they appear in the array, corresponding to the first valid pair found). Otherwise, output NO
.
Note: The implementation should use an efficient single-pass algorithm with a hash table to achieve optimal performance.
inputFormat
The input is read from standard input and is structured as follows:
- The first line contains an integer \(n\) denoting the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the array elements.
- The third line contains an integer \(T\) representing the target sum.
outputFormat
Output a single line to standard output. If there exists a pair of distinct integers in the array that add up to \(T\), print YES a b
where a
and b
are the two numbers. Otherwise, print NO
.
5
2 7 11 15 1
9
YES 2 7