Combination Sum
Given an array of candidates and a target, find all unique combinations that sum to the target, with repetition allowed.
Input format
The first line contains N and the target. The second line contains N distinct positive integers (candidates).
Output format
Print every unique combination summing to the target (numbers may repeat), one per line with the numbers in non-decreasing order. Sort the lines lexicographically as strings. If none exists, print -1.
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
3 7
2 3 6Expected output
2 2 3Example 2
Input
3 8
2 3 5Expected output
2 2 2 2
2 3 3
3 5