#K46627. Four Sum Problem

    ID: 28019 Type: Default 1000ms 256MiB

Four Sum Problem

Four Sum Problem

Given an array of integers and a target integer \(T\), find all unique quadruplets \([a, b, c, d]\) such that \(a + b + c + d = T\). Each quadruplet must be in non-decreasing order, and the solution set must not contain duplicate quadruplets. The array may include duplicate numbers so take care to avoid repeating combinations. An efficient algorithm is expected.

inputFormat

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 representing the array.

outputFormat

Print each unique quadruplet in a new line with the four numbers separated by a single space. The quadruplets should be output in lexicographical order (sorted ascending). If no quadruplet is found, print an empty line.

## sample
6 0
1 0 -1 0 -2 2
-2 -1 1 2

-2 0 0 2 -1 0 0 1

</p>