#C10473. Combination Sum II

    ID: 39682 Type: Default 1000ms 256MiB

Combination Sum II

Combination Sum II

You are given a list of integers and a target integer \(T\). Your task is to find all unique combinations in the list where the sum of the numbers equals \(T\). Each number in the list may be used at most once in each combination. The solution set must not contain duplicate combinations.

For example, given the list [2, 5, 2, 1, 2] and target 5, the unique combinations are:

  • [1,2,2]
  • [5]

All sums must satisfy the equation \(\sum_{i=1}^{k}a_i = T\).

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains a list of integers separated by spaces. (It may be empty, representing an empty list.)
  2. The second line contains a single integer representing the target sum (T).

outputFormat

Print the list of unique combinations (each combination is a list of integers) that sum to the target. The entire output should be printed as a Python-style list of lists. If no valid combination exists, print an empty list: [].## sample

2 3 6 7
7
[[7]]

</p>