#C8737. Three Elements Sum

    ID: 52752 Type: Default 1000ms 256MiB

Three Elements Sum

Three Elements Sum

You are given an array of integers and a target integer \(T\). Your task is to determine whether there exist three distinct elements \(a\), \(b\), and \(c\) in the array such that \(a + b + c = T\). This is a variant of the classic 3-sum problem. An efficient solution is expected with a time complexity of \(O(n^2)\) by sorting the array and then using a two-pointer approach.

inputFormat

The input is read from standard input (stdin) and consists of two lines. The first line contains two integers \(N\) and \(T\) where \(N\) is the number of elements in the array and \(T\) is the target sum. The second line contains \(N\) space-separated integers representing the array.

outputFormat

Output a single line to standard output (stdout) containing either YES if there exists three distinct elements in the array that add up to \(T\), or NO if no such triplet exists.

## sample
6 22
1 4 45 6 10 8
YES