#K86102. Skyline

    ID: 36790 Type: Default 1000ms 256MiB

Skyline

Skyline

Given N buildings aligned in a row with their heights provided, determine the skyline as seen from the right end. The skyline is defined such that for every index i (0-indexed), the output value is:

\(\text{skyline}[i] = \max_{i \le j < N} \{a_j\}\)

In other words, the ith number in the output is the maximum height among the buildings from i to the last building. If there are no buildings, output nothing.

Examples:

  • For input N = 5 and heights [4, 2, 3, 1, 5], the skyline is [5, 5, 5, 5, 5].
  • For input N = 4 and heights [1, 2, 3, 4], the skyline is [4, 4, 4, 4].

inputFormat

The first line of input contains a single integer N indicating the number of buildings. If N > 0, the second line contains N space-separated integers representing the heights of the buildings.

For example:

5
4 2 3 1 5

outputFormat

Output a single line containing N space-separated integers representing the skyline. If N=0, output nothing.

For example:

5 5 5 5 5
## sample
5
4 2 3 1 5
5 5 5 5 5