#P11074. Constructing a Dense Sequence
Constructing a Dense Sequence
Constructing a Dense Sequence
Given two positive integers \(n\) and \(m\), you are to construct a sequence \(a_1,a_2,\cdots,a_n\) of integers satisfying the following conditions:
- For every \(i\) with \(1\le i\le n\), we have \(0\le a_i<m\) (each \(a_i\) is an integer).
- For every pair of integers \(i,j\) with \(1\le i\le j\le n\), if we consider the prefix \(a_1, a_2, \ldots, a_j\) and sort it in increasing order (say \(b_1\le b_2\le \cdots \le b_j\)), then for every \(r\) from \(1\) to \(j\) we require \[ b_r \in \left[\frac{m(r-1)}{j},\frac{mr}{j}\right) \quad. \] In other words, when the interval \([0, m)\) is divided into \(j\) equal parts, each part must contain at least one element from the prefix.
If a sequence satisfying the conditions exists, output one such sequence (print the \(n\) numbers separated by a space in one line). Otherwise, output fire big
.
Note: It can be proved that a necessary condition for a solution to exist is \(n\le m\). In this problem, if \(n>m\) then no valid sequence exists.
inputFormat
The input consists of a single line containing two positive integers \(n\) and \(m\) separated by a space.
Constraints: \(1\le n, m\le 10\) (Note: the bounds are small to allow a backtracking solution.)
outputFormat
If there is a sequence satisfying the conditions, output \(n\) integers separated by a space in one line. Otherwise, output the string fire big
.
sample
3 5
1 4 2