Tinkoff Challenge - Final Round (Codeforces Round 414, rated, Div. 1 + Div. 2)
E
Choosing Carrot
Codeforces
2800
原题
← DF →
翻译中…

Oleg the bank client and Igor the analyst are arguing again. This time, they want to pick a gift as a present for their friend, ZS the coder. After a long thought, they decided that their friend loves to eat carrots the most and thus they want to pick the best carrot as their present.

翻译中…

There are $*n*$ carrots arranged in a line. The $*i*$-th carrot from the left has juiciness $*a*_{*i*}$. Oleg thinks ZS loves juicy carrots whereas Igor thinks that he hates juicy carrots. Thus, Oleg would like to maximize the juiciness of the carrot they choose while Igor would like to minimize the juiciness of the carrot they choose.

翻译中…

To settle this issue, they decided to play a game again. Oleg and Igor take turns to play the game. In each turn, a player can choose a carrot from either end of the line, and eat it. The game ends when only one carrot remains. Oleg moves first. The last remaining carrot will be the carrot that they will give their friend, ZS.

翻译中…

Oleg is a sneaky bank client. When Igor goes to a restroom, he performs $*k*$ moves before the start of the game. Each move is the same as above (eat a carrot from either end of the line). After Igor returns, they start the game with Oleg still going first.

翻译中…

Oleg wonders: for each $*k*$ such that $0 ≤ *k* ≤ *n* - 1$, what is the juiciness of the carrot they will give to ZS if he makes $*k*$ extra moves beforehand and both players play optimally?

翻译中…

Input

翻译中…

The first line of input contains a single integer $*n*$ ($1 ≤ *n* ≤ 3·10^{5}$) — the total number of carrots.

翻译中…

The next line contains $*n*$ space-separated integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($1 ≤ *a*_{*i*} ≤ 10^{9}$). Here $*a*_{*i*}$ denotes the juiciness of the $*i*$-th carrot from the left of the line.

翻译中…

Output

翻译中…

Output $*n*$ space-separated integers $*x*_{0}, *x*_{1}, ..., *x*_{*n* - 1}$. Here, $*x*_{*i*}$ denotes the juiciness of the carrot the friends will present to ZS if $*k* = *i*$.

翻译中…

Note

翻译中…

For the first example,

翻译中…

When $*k* = 0$, one possible optimal game is as follows:

翻译中…
  • Oleg eats the carrot with juiciness $1$.
  • Igor eats the carrot with juiciness $5$.
  • Oleg eats the carrot with juiciness $2$.
  • The remaining carrot has juiciness $3$.
翻译中…

When $*k* = 1$, one possible optimal play is as follows:

翻译中…
  • Oleg eats the carrot with juiciness $1$ beforehand.
  • Oleg eats the carrot with juiciness $2$.
  • Igor eats the carrot with juiciness $5$.
  • The remaining carrot has juiciness $3$.
翻译中…

When $*k* = 2$, one possible optimal play is as follows:

翻译中…
  • Oleg eats the carrot with juiciness $1$ beforehand.
  • Oleg eats the carrot with juiciness $2$ beforehand.
  • Oleg eats the carrot with juiciness $3$.
  • The remaining carrot has juiciness $5$.
翻译中…

When $*k* = 3$, one possible optimal play is as follows:

翻译中…
  • Oleg eats the carrot with juiciness $1$ beforehand.
  • Oleg eats the carrot with juiciness $2$ beforehand.
  • Oleg eats the carrot with juiciness $3$ beforehand.
  • The remaining carrot has juiciness $5$.
翻译中…

Thus, the answer is $3, 3, 5, 5$.

翻译中…

For the second sample, Oleg can always eat the carrot with juiciness $1$ since he always moves first. So, the remaining carrot will always have juiciness $1000000000$.

翻译中…

样例

Input #1
4
1 2 3 5
Output #1
3 3 5 5
InputCopy OutputCopy
Input #2
5
1000000000 1000000000 1000000000 1000000000 1
Output #2
1000000000 1000000000 1000000000 1000000000 1000000000
InputCopy OutputCopy
题目信息
题号
794E
时间限制
2 s
内存限制
256 MB
标签
博弈论
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。