#C5387. Combination Sum
Combination Sum
Combination Sum
You are given a set of distinct candidate integers and a target integer \(T\). Find all unique combinations of candidates where the chosen numbers sum to \(T\). You may choose the same candidate number an unlimited number of times.
Note: The combinations should be printed in lexicographical order with each combination in non-decreasing order. If no combination is possible, output a single line with the word Empty.
Example:
For candidates = [2, 3, 6, 7] and T = 7, the valid combinations are:
2 2 3
7
inputFormat
The input is read from standard input (stdin) with the following format:
- The first line contains an integer \(n\) representing the number of candidate elements.
- The second line contains \(n\) space-separated integers denoting the candidate values.
- The third line contains the target integer \(T\).
outputFormat
Print each unique combination which sums to \(T\) on a separate line. Within each line, print the numbers in the combination separated by a single space. The combinations must be printed in lexicographical order (i.e. sorted order considering each combination as a sequence of numbers). If there is no valid combination, print a single line with the word Empty.
## sample4
2 3 6 7
7
2 2 3
7
</p>