#P6608. Mystical Sequence Dream
Mystical Sequence Dream
Mystical Sequence Dream
E. Space had a strange dream. In his dream he saw a mysterious sequence \(a_1, a_2, \dots, a_n\) satisfying \(a_i \ge 0\) for all \(1\le i\le n\) with \(a_n \neq 0\). During the dream, he performed a series of operations on it. In each operation he chooses an index \(i\) for which \(a_i=i\) holds, then updates \(a_i\) to 0 and increases every previous element by 1 (i.e. for every \(1\le j < i\), set \(a_j = a_j+1\)). After exactly \(n+k\) operations, the sequence becomes the zero sequence: \(a_1=a_2=\cdots=a_n=0\).
Your task is: given two integers \(n\) and \(k\) (with \(n\ge 2\) and minimum feasibility condition \(k\ge n-2\)), output any initial sequence \(a_1, a_2, \dots, a_n\) (with \(a_n\neq0\) and \(\sum_{i=1}^n a_i=n+k\)) for which it is possible to perform a sequence of valid operations (as described above) so that after exactly \(n+k\) operations the sequence becomes all zeros.
Note: It can be proved that if an answer exists then there exists one that can be obtained by a reverse simulation process. One reverse operation is defined as follows: if the current state is \(b_1, b_2, \dots, b_n\), and if for some index \(i\) (with \(1\le i\le n\)) it holds that \(b_j\ge 1\) for all \(1\le j < i\), then we can revert an operation by updating for every \(1\le j < i\): \(b_j=b_j-1\) and setting \(b_i=i\). Starting from the final state (all zeros) and performing exactly \(n+k\) reverse moves (choosing at each step the largest index possible among those valid, or index 1 if none is available), one obtains a valid initial sequence. This is the intended method to construct a solution.
inputFormat
The input consists of a single line with two integers \(n\) and \(k\) separated by a space. It is guaranteed that \(n\ge 2\) and \(k\ge n-2\).
For example:
3 2
outputFormat
Output a line containing \(n\) non-negative integers \(a_1, a_2, \dots, a_n\) separated by spaces — a possible initial sequence satisfying the properties. The sequence must sum to \(n+k\) and its last element must be nonzero.
sample
2 0
0 2