#K73997. Taco Combination Sum
Taco Combination Sum
Taco Combination Sum
You are given an array of integers and a target integer \(T\). Your task is to find all unique combinations of numbers in the array that sum up to \(T\). Each number in the array may be used at most once in each combination.
The solution must read input from the standard input (stdin) and output the results to the standard output (stdout). If no valid combination exists, output a single line containing []
.
Note: The combinations in the output should be printed one per line, with the numbers in each combination separated by a single space.
For example, if the input array is [10, 1, 2, 7, 6, 5] and the target is 8, the valid combinations are:
- 1 2 5
- 1 7
- 2 6
inputFormat
The input will be given from stdin in the following format:
N num1 num2 ... numN T
Where:
N
is the number of elements in the array.- The second line contains
N
space-separated integers. T
is the target sum.
outputFormat
Print all unique combinations that sum up to the target T
. Each valid combination should be output on a separate line with the numbers separated by a space. If no combination is found, output []
on a single line.
6
10 1 2 7 6 5
8
1 2 5
1 7
2 6
</p>