#K57692. Pair with Target Sum

    ID: 30477 Type: Default 1000ms 256MiB

Pair with Target Sum

Pair with Target Sum

Given an array of integers and a target sum, determine whether there exist two distinct elements in the array that add up exactly to the target. This is a classic problem that can be efficiently solved using a hash set or sorting with two pointers.

Formally, given an integer \( n \) and a target value \( T \), and an array \( A \) of \( n \) integers, you need to decide if there exist two indices \( i \) and \( j \) (with \( i \neq j \)) such that:

[ a_i + a_j = T ]

If such a pair exists, print YES; otherwise, print NO.

Note: The solution should read input from standard input (stdin) and print the result to standard output (stdout).

inputFormat

The first line contains two space-separated integers: \( n \) (the number of elements in the array) and \( T \) (the target sum). The second line contains \( n \) space-separated integers representing the array elements.

outputFormat

Output a single line containing YES if there exist two distinct numbers in the array whose sum equals \( T \); otherwise, output NO.

## sample
5 9
1 2 3 4 5
YES