#C2309. Balanced Plate Stack

    ID: 45611 Type: Default 1000ms 256MiB

Balanced Plate Stack

Balanced Plate Stack

You are given n plates with weights and an extra parameter m (which is not used in the balancing logic). Your task is to determine if it is possible to reorder the plates so that the stack is balanced.

A stack is considered balanced if for every two consecutive plates with weights \(w_i\) and \(w_{i+1}\), the following condition holds:

[ L \leq \frac{w_{i+1}}{w_i} \leq U ]

If such a reordering exists, output the order of the plate weights (as space-separated integers) that satisfies the condition. Otherwise, output Not Possible.

Note: If there are multiple valid reorderings, you may output any one of them.

inputFormat

The input is read from stdin and consists of three lines:

  • The first line contains two integers n and m, where n is the number of plates.
  • The second line contains n space-separated integers representing the weights of the plates.
  • The third line contains two numbers L and U which define the valid ratio range between consecutive plates.

It is guaranteed that a solution, if it exists, involves a permutation of all given plate weights.

outputFormat

The output should be written to stdout as follows:

  • If a balanced ordering exists, output the weights in the valid order as a single line of space-separated integers.
  • If no valid ordering exists, output the string Not Possible.
## sample
3 500
2 4 8
2 2
2 4 8