#C1964. Four Sum Problem
Four Sum Problem
Four Sum Problem
Given an array of integers and a target value, your task is to find all unique quadruplets \((a, b, c, d)\) such that:
$$a + b + c + d = target$$
Each quadruplet must satisfy \(a \le b \le c \le d\). Output all quadruplets in lexicographically sorted order (i.e. each quadruplet is sorted in non-descending order, and the list of quadruplets is sorted). If there are no quadruplets that add up to the target, print -1.
Note: The same number may appear in the array multiple times, but each quadruplet must be unique.
inputFormat
The input is given via standard input (stdin). The first line contains two integers (n) and (target) separated by a space, where (n) is the number of elements in the array. The second line contains (n) space-separated integers representing the array elements.
outputFormat
Print each quadruplet that sums to the target on a separate line. Each quadruplet must be printed as four space-separated integers. The quadruplets should be output in lexicographically sorted order. If no quadruplet exists, print -1.## sample
6 0
1 0 -1 0 -2 2
-2 -1 1 2
-2 0 0 2
-1 0 0 1
</p>