#C3951. Quadruplet Sum Finder
Quadruplet Sum Finder
Quadruplet Sum Finder
You are given an array \( A \) of \( N \) integers and an integer \( X \). Your task is to find any quadruplet \( (a, b, c, d) \) from the array (using four distinct indices) such that:
\( a + b + c + d = X \)
If such a quadruplet exists, print the four numbers in non-decreasing order separated by a space. If more than one valid quadruplet exists, you may output any one of them. If no such quadruplet exists, print -1
.
Note: The elements in the quadruplet should come from distinct positions in the array, although their values might be the same.
inputFormat
The input is read from standard input (stdin) and has the following format:
T N1 X1 A1 A2 ... AN1 N2 X2 A1 A2 ... AN2 ... NT XT A1 A2 ... ANT
Here, \( T \) is the number of test cases. For each test case, the first line contains two integers \( N \) and \( X \) where \( N \) is the number of elements in the array and \( X \) is the target sum. The second line contains \( N \) space-separated integers representing the array \( A \).
outputFormat
For each test case, print a single line to standard output (stdout):
- If a quadruplet exists, output four space-separated integers in non-decreasing order such that their sum is \( X \).
- If no valid quadruplet exists, output
-1
.
1
6 10
1 2 3 4 5 6
1 2 3 4