#C3092. Three Sum Existence Check

    ID: 46481 Type: Default 1000ms 256MiB

Three Sum Existence Check

Three Sum Existence Check

Problem Description:

You are given an array of N integers. Your task is to determine whether there exists any triplet \(a, b, c\) such that they satisfy the equation:

\(a + b + c = T\)

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

The array may contain negative numbers as well as positive numbers. An efficient solution is expected with a time complexity close to \(O(N^2)\) using sorting and the two-pointer technique.

inputFormat

Input Format:

The input consists of three lines:

  • The first line contains an integer \(N\), the number of elements in the array.
  • The second line contains \(N\) space-separated integers representing the array elements.
  • The third line contains an integer \(T\), the target sum.

outputFormat

Output Format:

Print a single line with the string YES if a triplet exists whose sum equals \(T\), otherwise print NO.

## sample
6
1 2 3 4 5 6
10
YES