#K81747. Triplet Sum Finder
Triplet Sum Finder
Triplet Sum Finder
This problem requires you to find three distinct elements in an array whose sum equals a given target value. If such a triplet exists, output the three values in ascending order formatted as (a, b, c)
; otherwise, output an empty tuple formatted as ()
. The mathematical condition can be written in \(\LaTeX\) as: \(a+b+c=T\), where \(T\) is the target.
Note: The three elements must be chosen from different positions in the array.
inputFormat
The input is given via stdin and consists of the following:
- 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 the triplet as a tuple in ascending order, formatted as (a, b, c)
, if one exists. If no such triplet is found, output an empty tuple: ()
.
6 24
12 3 6 1 6 9
(3, 9, 12)