#P11066. Elevator Reordering

    ID: 13121 Type: Default 1000ms 256MiB

Elevator Reordering

Elevator Reordering

A building with n floors and m elevators is given. Initially the i-th elevator is stationary at floor \(i\). You are given a permutation \(p\) of \(\{1,2,\dots,m\}\); your task is to reposition the elevators so that the i-th elevator ends up at floor \(p_i\>.

You may perform two types of operations:

  • 0: Let time advance by one moment.
  • x: For a positive integer \(x\le n\). When executing such an operation, the following conditions must hold:
    • There is no stationary elevator at floor \(x\).
    • If we define the distance between a stationary elevator at floor \(z\) and floor \(x\) as \(|x-z|\), then the stationary elevator whose distance to \(x\) is minimized exists and is unique.
    When you execute operation \(x\), let \(y\) be the index of the unique nearest stationary elevator (which is at floor \(z\)). Then elevator \(y\) immediately begins moving and, after a delay of \(|x-z|\) moments (i.e. before any subsequent operation), it reaches floor \(x\) and becomes stationary.

Note: At any moment, no two stationary elevators may occupy the same floor.

For each test case, a scoring parameter \(o\) is provided; you must construct a sequence of operations whose total count does not exceed \(o\). This problem uses a custom validator, so if there are multiple valid solutions, output any one.

inputFormat

The first line contains three integers \(n\), \(m\), and \(o\).

The second line contains \(m\) distinct integers \(p_1, p_2, \dots, p_m\), which form a permutation of \(\{1,2,\dots,m\}\).

outputFormat

Output a sequence of operations (each operation is either the digit 0 or a positive integer \(x\)) separated by spaces or newlines. When these operations are executed in order under the rules described, the final configuration must have the i-th elevator at floor \(p_i\), and the total number of operations must not exceed \(o\).

If multiple valid solutions exist, output any one.

sample

5 3 10
1 2 3