luogu#P5155. [USACO18DEC] Balance Beam P

[USACO18DEC] Balance Beam P

Problem Description

To save money to build a new stall in her barn, Bessie starts performing at a local circus, showing off her excellent balance by carefully walking back and forth on a balance beam.

How much money Bessie can earn depends on the position where she finally jumps off the beam successfully. Positions on the beam from left to right are labeled 0,1,,N+10,1,\ldots,N+1. If Bessie reaches position 00 or N+1N+1, she will fall off the end of the beam and unfortunately receive no reward.

If Bessie is at a given position kk, she may do either of the following:

  1. Toss a coin. If it lands tails up, she moves to position k1k-1; if it lands heads up, she moves to position k+1k+1 (that is, each happens with probability 1/21/2).

  2. Jump off the beam and receive a reward of f(k)f(k) (0f(k)1090 \leq f(k) \leq 10^9).

Bessie realizes she cannot guarantee getting any particular reward, since her movement is controlled by the random coin tosses. However, based on her starting position, she wants to compute the expected reward she can obtain after making a sequence of optimal decisions (where “optimal” means the decisions that yield the highest possible expected reward).

For example, if her strategy gives her a reward of 1010 with probability 1/21/2, a reward of 88 with probability 1/41/4, and a reward of 00 with probability 1/41/4, then her expected reward is the weighted average 10×(1/2)+8×(1/4)+0×(1/4)=710 \times (1/2)+8 \times (1/4)+0 \times (1/4)=7.

Input Format

The first line of input contains NN (2N1052 \leq N \leq 10^5). The next NN lines contain f(1)f(N)f(1) \ldots f(N).

Output Format

Output NN lines. On the ii-th line, output 10510^5 times the expected reward Bessie can obtain when starting from position ii and using an optimal strategy, rounded down.

2
1
3
150000
300000

Hint

Translated by ChatGPT 5