LCC '25 Contest 2 S5 - Happy (Part 1)

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 0.6s
Python 2.0s
Memory limit: 256M

Author:
Problem type

This problem is worth 30% of the 100 points allocated to S5

Consider an array of length N, filled with positive integers from the range 1 to N, inclusive (the array does not necessarily need to contain every number, however).

An array with maximum element x_i is considered happy under the following conditions:

  1. All of its elements lie in the range 1 to x_i
  2. Each number from the range 1 to x_i occur at least once in the array
  3. The first occurence of the positive integer i (1 \leq i < x_i) lies before the first occurence of the positive integer i+1.

Brian hands you over the length N, and tells you to find the M^{th} happy array sorted in ascending lexographical order (as in, starting from the array of all 1's).

Input Specification

There is one line of input containing two space-separated integers N, M, 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 N space-separated integers, representing the happy array asked for.

Constraints

Marks Allocated Bounds on N Bounds on M
10\% N = 3 1 \leq M \leq 5
20\% 1 \leq N \leq 10 1 \leq M \leq 50
70\% 1 \leq N \leq 10^5 1 \leq M \leq 10^7

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

There are no comments at the moment.