#C11361. Sunset Views
Sunset Views
Sunset Views
In this problem, you are given a list of integers representing the heights of buildings ordered from east to west. A building is said to have a sunset view if there are no taller buildings to its west. Formally, let the building heights be (a_1, a_2, \ldots, a_n) where (a_1) is the easternmost and (a_n) is the westernmost. A building (a_i) has a sunset view if (a_i > \max{a_{i+1}, a_{i+2}, \ldots, a_n}) (if such buildings exist). Your task is to output the heights of the buildings that have a sunset view in order from west to east.
inputFormat
The first line of input contains an integer (n) (where (n \ge 0)) — the number of buildings. The second line contains (n) space-separated integers representing the heights of the buildings from east to west.
outputFormat
Output a single line containing the heights of the buildings that have a sunset view, from west to east, separated by a single space. If no building is provided (i.e. (n = 0)), output an empty line.## sample
4
4 2 3 1
1 3 4
</p>