#K80452. Pair Sum Problem

    ID: 35533 Type: Default 1000ms 256MiB

Pair Sum Problem

Pair Sum Problem

You are given an array of integers and a target sum \( k \). Your task is to determine whether there exists a pair of distinct elements in the array that adds up to \( k \). If such a pair exists, output YES; otherwise, output NO.

Example:

  • For n = 5, k = 16 and the array [1, 4, 45, 6, 10], since \( 6+10=16 \), the answer is YES.

This problem is a variant of the classic two-sum problem and can be optimally solved using hash tables with an expected time complexity of \( O(n) \).

inputFormat

The first line of the input contains two integers \( n \) (the number of elements in the array) and \( k \) (the target sum), separated by a space.

The second line contains \( n \) space-separated integers representing the elements of the array.

outputFormat

Output a single line with the string YES if there exists a pair in the array whose sum is equal to \( k \). Otherwise, output NO.

## sample
5 16
1 4 45 6 10
YES