#K38117. Combination Sum II
Combination Sum II
Combination Sum II
You are given a list of n integers and a target integer target. Your task is to find all unique combinations of the list whose sum is equal to the target. Each number in the list can be used at most once in the combination and the solution must not contain duplicate combinations.
This can be formalized as: find all subsets S of the given list such that $$\sum_{x\in S} x = target.$$
Note: The combinations in the output must be printed in lexicographical order. For example, given the list [10, 1, 2, 7, 6, 1, 5] and target = 8, one valid solution is:
1 1 6 1 2 5 1 7 2 6
inputFormat
The input consists of two lines:
- The first line contains two integers n and target, where n is the number of elements in the list, and target is the target sum.
- The second line contains n space-separated integers representing the list.
outputFormat
The output should be printed to stdout. On the first line, print an integer K representing the number of unique combinations. Then, print each combination on a separate line with its elements separated by a single space. The combinations must be sorted in lexicographical order.
## sample7 8
10 1 2 7 6 1 5
4
1 1 6
1 2 5
1 7
2 6
</p>