#C4511. Find Triplet with Given Sum
Find Triplet with Given Sum
Find Triplet with Given Sum
You are given a list of integers and a target sum \(T\). Your task is to find three distinct integers from the list such that their sum is exactly equal to \(T\). If such a triplet exists, output the three integers in non-decreasing order separated by spaces in one line. If there are multiple answers, any valid triplet is acceptable. If no such triplet exists, output -1.
Note: The input will be provided via standard input (stdin) and the output must be printed to standard output (stdout). Please ensure your solution reads from stdin and writes to stdout.
inputFormat
The first line of input contains two integers \(n\) and \(T\), where \(n\) is the number of elements in the list and \(T\) is the target sum. The second line contains \(n\) space-separated integers.
Example:
6 24 12 3 4 1 6 9
outputFormat
If a valid triplet is found, output three space-separated integers in non-decreasing order on a single line. Otherwise, output -1.
Example Output:
3 9 12## sample
6 24
12 3 4 1 6 9
3 9 12
</p>