#K58687. Three Number Sum
Three Number Sum
Three Number Sum
You are given an array of integers and a target sum \( T \). Your task is to find three distinct numbers \( a, b, c \) in the array such that their sum equals \( T \), i.e. \( a + b + c = T \). If such a triplet exists, output the three numbers in ascending order separated by spaces; otherwise, output -1.
The problem requires you to achieve an efficient solution, typically in \( O(n^2) \) time, by first sorting the array and then using a two-pointer technique to check for valid triplets.
inputFormat
The input is given from standard input (stdin) and has the following format:
n a1 a2 a3 ... an T
Where:
- n is a positive integer representing the number of elements in the array.
- a1, a2, ..., an are the integers in the array.
- T is the target sum.
outputFormat
If a valid triplet exists, output the three numbers separated by a single space on one line. If no such triplet exists, output -1.
## sample6
1 2 3 4 5 6
10
1 3 6