#P3566. Reassembling the Brick Line
Reassembling the Brick Line
Reassembling the Brick Line
Little Bitie once built a line of colorful bricks where no two adjacent bricks shared the same color. After an unfortunate fall, the bricks became disordered. Bitie managed to sort the bricks by color and recalled the colors of the two end bricks. Your task is to help him reconstruct the original line under the following conditions:
- The total number of bricks is \(n = \sum_{i=1}^{k} count[i]\), where \(k\) is the number of distinct colors and \(count[i]\) is the number of bricks of color \(i\).
- The first brick must be of color \(L\) and the last brick must be of color \(R\).
- No two adjacent bricks can have the same color, i.e., for all valid \(i\), \(a_i \neq a_{i+1}\).
If it is impossible to reconstruct such a line (Bitie might have misremembered the end colors or some bricks are missing), print No solution
.
inputFormat
The input consists of three lines:
- An integer \(k\) representing the number of different colors.
- \(k\) space-separated positive integers representing the counts for colors 1 through \(k\) respectively.
- Two integers \(L\) and \(R\) (each between 1 and \(k\)) representing the colors of the leftmost and rightmost bricks.
outputFormat
If a valid reconstruction exists, print a single line containing the colors of the bricks in order (space‐separated). If no valid arrangement exists, output No solution
.
sample
3
3 2 1
1 3
1 2 1 2 1 3
</p>