#K80592. Find Pair with Given Sum

    ID: 35564 Type: Default 1000ms 256MiB

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:

  1. The first line contains an integer \(n\) denoting the number of elements in the array.
  2. The second line contains \(n\) space-separated integers representing the array elements.
  3. 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.

## sample
5
2 7 11 15 1
9
YES 2 7