CF794E.Choosing Carrot

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn carrots arranged in a line. The ii -th carrot from the left has juiciness aia_{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 kk 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 kk such that 0<=k<=n10<=k<=n-1 , what is the juiciness of the carrot they will give to ZS if he makes kk extra moves beforehand and both players play optimally?

输入格式

The first line of input contains a single integer nn ( 1<=n<=31051<=n<=3·10^{5} ) — the total number of carrots.

The next line contains nn space-separated integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 1<=ai<=1091<=a_{i}<=10^{9} ). Here aia_{i} denotes the juiciness of the ii -th carrot from the left of the line.

输出格式

Output nn space-separated integers x0,x1,...,xn1x_{0},x_{1},...,x_{n-1} . Here, xix_{i} denotes the juiciness of the carrot the friends will present to ZS if k=ik=i .

输入输出样例

  • 输入#1

    4
    1 2 3 5
    

    输出#1

    3 3 5 5
    
  • 输入#2

    5
    1000000000 1000000000 1000000000 1000000000 1
    

    输出#2

    1000000000 1000000000 1000000000 1000000000 1000000000
    

说明/提示

For the first example,

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

  • Oleg eats the carrot with juiciness 11 .
  • Igor eats the carrot with juiciness 55 .
  • Oleg eats the carrot with juiciness 22 .
  • The remaining carrot has juiciness 33 .

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

  • Oleg eats the carrot with juiciness 11 beforehand.
  • Oleg eats the carrot with juiciness 22 .
  • Igor eats the carrot with juiciness 55 .
  • The remaining carrot has juiciness 33 .

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

  • Oleg eats the carrot with juiciness 11 beforehand.
  • Oleg eats the carrot with juiciness 22 beforehand.
  • Oleg eats the carrot with juiciness 33 .
  • The remaining carrot has juiciness 55 .

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

  • Oleg eats the carrot with juiciness 11 beforehand.
  • Oleg eats the carrot with juiciness 22 beforehand.
  • Oleg eats the carrot with juiciness 33 beforehand.
  • The remaining carrot has juiciness 55 .

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

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

首页