N and M (10)
Time limit1sMemory limit512 MB
Given N numbers and an M, print every non-decreasing length-M selection of the numbers in lexicographic order without duplicates.
- Level
Easy3 of 10
- Topics
- Backtracking, Sorting, Implementation, Recursion
- Solved
- No attempts yet
Problem
You are given natural numbers and a natural number . Write a program that finds every sequence of length satisfying both conditions below.
- The sequence consists of numbers chosen from the given numbers.
- The chosen sequence is non-decreasing. A sequence of length is non-decreasing when holds.
Input
The first line contains and . ()
The second line contains numbers. Every number in the input is a natural number no greater than 10,000.
Output
Print one sequence that satisfies the conditions per line. Do not print the same sequence more than once, and separate the elements of a sequence with spaces.
Print the sequences in increasing lexicographic order.