CF1313C1.Skyscrapers (easy version)

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

This is an easier version of the problem. In this version n1000n \le 1000

The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the company has already bought nn plots along the highway and is preparing to build nn skyscrapers, one skyscraper per plot.

Architects must consider several requirements when planning a skyscraper. Firstly, since the land on each plot has different properties, each skyscraper has a limit on the largest number of floors it can have. Secondly, according to the design code of the city, it is unacceptable for a skyscraper to simultaneously have higher skyscrapers both to the left and to the right of it.

Formally, let's number the plots from 11 to nn . Then if the skyscraper on the ii -th plot has aia_i floors, it must hold that aia_i is at most mim_i ( 1aimi1 \le a_i \le m_i ). Also there mustn't be integers jj and kk such that j<i<kj < i < k and aj>ai<aka_j > a_i < a_k . Plots jj and kk are not required to be adjacent to ii .

The company wants the total number of floors in the built skyscrapers to be as large as possible. Help it to choose the number of floors for each skyscraper in an optimal way, i.e. in such a way that all requirements are fulfilled, and among all such construction plans choose any plan with the maximum possible total number of floors.

输入格式

The first line contains a single integer nn ( 1n10001 \leq n \leq 1000 ) — the number of plots.

The second line contains the integers m1,m2,,mnm_1, m_2, \ldots, m_n ( 1mi1091 \leq m_i \leq 10^9 ) — the limit on the number of floors for every possible number of floors for a skyscraper on each plot.

输出格式

Print nn integers aia_i — the number of floors in the plan for each skyscraper, such that all requirements are met, and the total number of floors in all skyscrapers is the maximum possible.

If there are multiple answers possible, print any of them.

输入输出样例

  • 输入#1

    5
    1 2 3 2 1

    输出#1

    1 2 3 2 1
  • 输入#2

    3
    10 6 8

    输出#2

    10 6 6

说明/提示

In the first example, you can build all skyscrapers with the highest possible height.

In the second test example, you cannot give the maximum height to all skyscrapers as this violates the design code restriction. The answer [10,6,6][10, 6, 6] is optimal. Note that the answer of [6,6,8][6, 6, 8] also satisfies all restrictions, but is not optimal.

首页