LCC '25 Contest 2 S5 - Happy (Part 1)
View as PDFThis problem is worth 30% of the 100 points allocated to S5
Consider an array of length , filled with positive integers from the range
to
, inclusive (the array does not necessarily need to contain every number, however).
An array with maximum element is considered happy under the following conditions:
- All of its elements lie in the range
to
- Each number from the range
to
occur at least once in the array
- The first occurence of the positive integer
lies before the first occurence of the positive integer
.
Brian hands you over the length , and tells you to find the
happy array sorted in ascending lexographical order (as in, starting from the array of all
).
Input Specification
There is one line of input containing two space-separated integers , representing the number of elements in the array and the happy array you are asked to find. It is guaranteed that there exists such a happy array.
Output Specification
Output a line, containing space-separated integers, representing the happy array asked for.
Constraints
| Marks Allocated | Bounds on |
Bounds on |
|---|---|---|
Sample Input 1
4 5
Sample Output 1
1 1 2 3
Sample Explanation 1
The five lexographically least happy arrays, in ascending order are the following: 1 1 1 1 1 1 1 2 1 1 2 1 1 1 2 2 1 1 2 3. Keep in mind that 1 1 1 3 is not a happy array.
Comments