#C10496. Quadruplets Sum Finder
Quadruplets Sum Finder
Quadruplets Sum Finder
Given an array of integers and a target sum \(T\), your task is to find all unique quadruplets \(a, b, c, d\) in the array such that \(a+b+c+d=T\). Each quadruplet must be printed in ascending lexicographical order (i.e. sorted by their elements).
Note that the array can contain duplicate numbers, but each quadruplet in the output must be unique. It is required that you implement an efficient algorithm utilizing sorting and the two-pointer technique.
inputFormat
The input is given from standard input (stdin) and consists of three lines:
- The first line contains an integer \(n\), the number of integers in the array.
- The second line contains \(n\) space-separated integers.
- The third line contains the target sum \(T\).
outputFormat
Output to standard output (stdout) the list of quadruplets. Each quadruplet should be printed on a new line with the four integers separated by a single space. If no quadruplet exists, output nothing.
## sample6
1 0 -1 0 -2 2
0
-2 -1 1 2
-2 0 0 2
-1 0 0 1
</p>