#K69322. 4Sum Quadruplets

    ID: 33061 Type: Default 1000ms 256MiB

4Sum Quadruplets

4Sum Quadruplets

Given an array of integers and a target integer \(T\), your task is to find all unique quadruplets \([a, b, c, d]\) such that:

\(a + b + c + d = T\)

with the condition that\( \;a \le b \le c \le d\). Each quadruplet must be unique and the resulting list of quadruplets should be printed in lexicographically sorted order. Use efficient algorithms to handle large inputs.

inputFormat

Input is read from standard input (stdin). 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.

outputFormat

Print each quadruplet on a separate line. Within a line, the four integers are space-separated and must be in non-decreasing order. The quadruplets should be output in lexicographically sorted order. If no valid quadruplet exists, do not print anything.## sample

6 0
1 0 -1 0 -2 2
-2 -1 1 2

-2 0 0 2 -1 0 0 1

</p>