#C12844. Three Sum Target

    ID: 42316 Type: Default 1000ms 256MiB

Three Sum Target

Three Sum Target

Given an array of integers, determine whether there exists a triplet of distinct integers in the array whose sum equals a given target value. The solution should be optimized using efficient techniques such as sorting and the two-pointer method. In mathematical terms, for an array \(A\) of length \(n\), find if there exist indices \(i, j, k\) with \(i < j < k\) such that:

\(A[i] + A[j] + A[k] = target\)

The array may include negative numbers and zero, so your algorithm must handle all cases correctly.

inputFormat

The input is given via standard input (stdin) in the following format:

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

outputFormat

Output a single line to standard output (stdout) containing either True if there exists a triplet whose sum equals the target, or False otherwise.

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