#K71167. Buildings with Sunset Views

    ID: 33472 Type: Default 1000ms 256MiB

Buildings with Sunset Views

Buildings with Sunset Views

You are given a sequence of building heights arranged from left to right. A building can see the sunset if it is strictly taller than every building to its left. Your task is to determine the indices of all buildings that can see the sunset. The buildings are indexed starting from 0.

For example, consider the building heights: [7, 4, 8, 2, 9, 3, 11].

Explanation: The first building (height = 7) can see the sunset. The second building (height = 4) is blocked by the first building. The third building (height = 8) is taller than 7 so it can see the sunset. The fourth building (height = 2) is blocked by 8. The fifth building (height = 9) is taller than 8 so it can see the sunset. The sixth building (height = 3) is blocked by 9, and finally, the seventh building (height = 11) is taller than 9 so it is visible. Thus, the answer is: [0, 2, 4, 6].

Note: If there are no buildings, output an empty result.

The underlying condition can be expressed in LaTeX as: \(A[i] > \max\{A[0], A[1], \dots, A[i-1]\}\) for building \(i\) to see the sunset.

inputFormat

The input is provided via standard input (stdin) in the following format:

  • The first line contains an integer \(n\) representing the number of buildings.
  • The second line contains \(n\) integers, separated by spaces, representing the heights of the buildings.

If \(n = 0\), the second line may be empty.

outputFormat

Output via standard output (stdout) a single line containing the indices of the buildings that can see the sunset. The indices should be output in increasing order and separated by a single space. If no building can see the sunset, output an empty line.

## sample
7
7 4 8 2 9 3 11
0 2 4 6