#K79537. Triplet Sum to Target

    ID: 35330 Type: Default 1000ms 256MiB

Triplet Sum to Target

Triplet Sum to Target

Given an array of integers and a target sum \(T\), determine whether there exists a triplet \( (a_i, a_j, a_k) \) in the array such that \( a_i + a_j + a_k = T \). This problem can be efficiently solved by first sorting the array and then using the two-pointer technique with a time complexity of \(O(n^2)\).

Input details: The first line of input is an integer \(n\), representing the number of array elements. The second line contains \(n\) space-separated integers. The third line contains the target integer \(T\). Output a single line "True" if such a triplet exists, and "False" otherwise.

inputFormat

The input is read from standard input (stdin) and consists of three parts:

  • A single integer \(n\) representing the number of elements in the array.
  • A line with \(n\) space-separated integers.
  • A single integer \(T\) representing the target sum.

outputFormat

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

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