#P9066. Firefly Pursuit

    ID: 22225 Type: Default 1000ms 256MiB

Firefly Pursuit

Firefly Pursuit

At nightfall, fireflies in a forest embark on a mysterious journey along a straight path (which can be viewed as a number line). Initially, there are \(n\) fireflies placed at distinct integer coordinates \(x_1, x_2, \dots, x_n\) (from left to right, indexed from 1 to \(n\)). The \(i\)th firefly has a unique brightness \(a_i\>.

At any moment, every living firefly \(i\) acts as follows:

  • Among the currently living fireflies, identify its adjacent neighbor(s) (neighbors are those pairs between which there is no other living firefly). Let \(j\) be the one with the maximum brightness among them.
  • If \(a_i < a_j\), then firefly \(i\) flies toward firefly \(j\) at a speed of 1 unit per second; otherwise, it stays in its current position.

When two fireflies meet (i.e. their coordinates become equal), the one with the lower brightness expires instantly. It can be shown that in the end, only one firefly (the one with the highest brightness) survives.

Your task is: for every firefly except the surviving one, determine the coordinate at which it dies. Note that all death collisions occur when a firefly finally converges with the surviving, stationary firefly (which, by the problem conditions, is the one with the maximum brightness).

Observation: Since the firefly with the maximum brightness never moves, every other firefly eventually moves toward it and dies at its coordinate.

Formally: Let \(m\) be the index such that \(a_m = \max\{a_1, a_2, \dots, a_n\}\). Then every firefly \(i\) with \(i\neq m\) dies at the coordinate \(x_m\>.

inputFormat

The input consists of three lines:

  1. The first line contains a single integer \(n\) (the number of fireflies).
  2. The second line contains \(n\) space‐separated integers \(x_1, x_2, \dots, x_n\) representing the initial positions of the fireflies (in strictly increasing order).
  3. The third line contains \(n\) space‐separated integers \(a_1, a_2, \dots, a_n\) representing the brightness of each firefly. All brightness values are distinct.

outputFormat

Output \(n-1\) integers in one line, where each integer is the coordinate at which the corresponding firefly (except the survivor) expires. The order of output should follow the original indices of the fireflies (skipping the surviving one).

sample

3
1 3 5
1 3 2
3 3