#K52132. Pair Formation Problem

    ID: 29242 Type: Default 1000ms 256MiB

Pair Formation Problem

Pair Formation Problem

Given an array of n integers and a target integer k, determine whether it is possible to partition the array into non-overlapping pairs such that the sum of the numbers in each pair is exactly k. Each element may be used in at most one pair. Note that if n is odd, it is impossible to form pairs using all elements.

Formally, you are given an array a[1...n]. Check if there exists a pairing of the indices into n/2 pairs (i, j) (with i ≠ j) so that for every pair, the equality \(a_i + a_j = k\) holds.

inputFormat

The first line of input contains two integers n and k (1 ≤ n ≤ 105, |k| ≤ 109), representing the number of elements in the array and the target sum, respectively. The second line contains n space-separated integers representing the array elements.

outputFormat

Output a single line containing either "YES" if it is possible to form the pairs as described or "NO" if it is not possible.## sample

6 8
1 7 2 6 3 5
YES