#K72672. Find Pair with Sum

    ID: 33806 Type: Default 1000ms 256MiB

Find Pair with Sum

Find Pair with Sum

You are given n boxes, each containing a certain number of candies. Your task is to determine whether there exists a pair of boxes such that the sum of the candies in these two boxes is equal to a given target k. In other words, given a list \(a_1, a_2, \dots, a_n\) and a target value \(k\), you need to decide if there exist two distinct indices \(i\) and \(j\) with \(1 \leq i, j \leq n\) such that

[ a_i + a_j = k ]

Output YES if such a pair exists, and NO otherwise.

inputFormat

The input is given via stdin and consists of two lines:

  • The first line contains two integers separated by spaces: n (the number of boxes) and k (the target sum).
  • The second line contains n space-separated integers, where the \(i\)-th integer represents the number of candies in the \(i\)-th box.

outputFormat

Print a single line to stdout: YES if there exists a pair of boxes whose candy counts sum up to k, or NO otherwise.

## sample
5 10
1 2 3 7 8
YES