1313C1.md (2720B)
1 Source: https://codeforces.com/problemset/problem/1313/C1 2 3 C1. Skyscrapers (easy version) 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 512 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 This is an easier version of the problem. In this version $n \le 1000$ 22 23 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 $n$ plots along the highway and is preparing to build $n$ skyscrapers, one skyscraper per plot. 24 25 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. 26 27 Formally, let's number the plots from $1$ to $n$. Then if the skyscraper on the $i$-th plot has $a_i$ floors, it must hold that $a_i$ is at most $m_i$ ($1 \le a_i \le m_i$). Also there mustn't be integers $j$ and $k$ such that $j \lt i \lt k$ and $a_j \gt a_i \lt a_k$. Plots $j$ and $k$ are not required to be adjacent to $i$. 28 29 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. 30 31 Input 32 33 The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of plots. 34 35 The second line contains the integers $m_1, m_2, \ldots, m_n$ ($1 \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. 36 37 Output 38 39 Print $n$ integers $a_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. 40 41 If there are multiple answers possible, print any of them. 42 43 Examples 44 45 Input 46 47 ``` 48 5 49 1 2 3 2 1 50 ``` 51 52 Output 53 54 ``` 55 1 2 3 2 1 56 ``` 57 58 Input 59 60 ``` 61 3 62 10 6 8 63 ``` 64 65 Output 66 67 ``` 68 10 6 6 69 ``` 70 71 Note 72 73 In the first example, you can build all skyscrapers with the highest possible height. 74 75 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]$ is optimal. Note that the answer of $[6, 6, 8]$ also satisfies all restrictions, but is not optimal.