#C11683. Find Triplet Sum

    ID: 41026 Type: Default 1000ms 256MiB

Find Triplet Sum

Find Triplet Sum

Given an array of integers, your task is to determine if there exists a triplet \( (a, b, c) \) such that \( a + b + c = target \). Each triplet must consist of three distinct elements from the array. The array may contain duplicate numbers and is not necessarily sorted.

You can use efficient algorithms such as sorting combined with the two-pointer technique to handle large input sizes. The mathematical condition to check is given by \( \sum_{i=1}^{3} a_i = target \).

inputFormat

Input is provided via standard input (stdin). The first line contains an integer \( T \) representing the number of test cases. Each test case consists of three parts:

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

outputFormat

For each test case, output a single line to standard output (stdout) with \( True \) if there exists any triplet in the array that sums to \( target \); otherwise, print \( False \).

## sample
3
6
1 4 45 6 10 8
22
6
12 3 4 1 6 9
24
5
1 2 3 4 5
50
True

True False

</p>