#C9262. Unique Goodies Sets
Unique Goodies Sets
Unique Goodies Sets
You are given a set of goodies and a positive integer n. Your task is to generate all unique combinations (or sets) of goodies such that each combination contains exactly n items. The combinations must be derived from the sorted order of the goodies (i.e. lexicographical order) and output one combination per line with the items separated by a single space.
More formally, given an integer \( n \) and a list of strings, first sort the list in lexicographical order; then, output every combination of \( n \) distinct goodies. If no such combination exists (for example, when the list is empty), output nothing.
Note: Sorting is performed using the default lexicographical order.
inputFormat
The input is read from standard input and has the following format:
<n> <k> item1 item2 ... itemk
where:
- n is the number of items each combination should contain.
- k is the number of available goodies.
- Each of the following k lines contains a non-empty string representing a goodie.
outputFormat
Output all unique combinations of n goodies computed from the sorted list. Each combination should be printed on a separate line, with the goodies separated by a single space. If no combination exists, output nothing.
## sample2
4
pen
notebook
mug
sticker
mug notebook
mug pen
mug sticker
notebook pen
notebook sticker
pen sticker
</p>