#C14375. Combination Sum Finder
Combination Sum Finder
Combination Sum Finder
Given a list of positive integers (which can be empty) and a target sum, find all unique combinations of numbers that add up to the target. Each combination must have its elements in non‐descending order, and the entire list of combinations should be sorted in lexicographical order. A number may be chosen from the list an unlimited number of times. For example, with the input list [2, 3, 6, 7]
and target 7
, the valid combinations are [[2, 2, 3], [7]]
. When the target is 0, the only valid combination is the empty combination: [[]]
.
The solution must read input from standard input (stdin) and output the result to standard output (stdout) in the Python list format.
inputFormat
The input consists of two lines:
-
The first line contains space-separated integers representing the list. This line can be empty, indicating an empty list.
-
The second line contains a single integer representing the target sum.
outputFormat
Output a single line representing the list of combinations in Python list format. Each combination is a list of integers. If there is no valid combination, output an empty list: [].## sample
2 3 6 7
7
[[2, 2, 3], [7]]