#C6946. Three Sum Existence Problem

    ID: 50762 Type: Default 1000ms 256MiB

Three Sum Existence Problem

Three Sum Existence Problem

You are given an array of integers and a target integer k. Determine whether there exist three distinct integers in the array such that their sum equals the target k. In mathematical terms, you need to check if there exist indices i, j, and l with i ≠ j ≠ l such that

$$a + b + c = k$$

If such a triplet exists, output YES; otherwise, output NO.

You need to handle multiple test cases.

inputFormat

The first line contains an integer T, the number of test cases. Each test case consists of two lines:

  • The first line has two integers n and k, where n is the size of the array and k is the target sum.
  • The second line contains n space-separated integers representing the array elements.

outputFormat

For each test case, output a single line containing either YES if there exists a triplet that sums up to k, or NO if there is no such triplet.

## sample
1
4 6
1 2 3 4
YES

</p>