#K89342. Combination Sum: Find All Unique Combinations

    ID: 37509 Type: Default 1000ms 256MiB

Combination Sum: Find All Unique Combinations

Combination Sum: Find All Unique Combinations

In this problem, you are given an array of integers and a target sum (T). Your task is to find all unique combinations from the array where the sum of the elements equals (T). Each element in the array may be used an unlimited number of times. The resulting combinations must be output in lexicographical order.

For example, given the array [2, 3, 6, 7] and target 7, the valid combinations are [2, 2, 3] and [7].

Note: Two combinations are considered unique if they differ in at least one element or in the frequency of an element.

inputFormat

The input is provided via standard input (stdin) and consists of three parts:

1. The first line contains a single integer (n), denoting the number of elements in the array.
2. The second line contains (n) space-separated integers representing the array elements.
3. The third line contains a single integer representing the target sum (T).

outputFormat

Output all unique combinations that sum up to the target (T) to standard output (stdout). Each combination should be printed on a new line with its numbers separated by a single space. If no valid combination exists, output nothing.## sample

4
2 3 6 7
7
2 2 3

7

</p>