#C12903. Buildings with Sunset View
Buildings with Sunset View
Buildings with Sunset View
You are given the heights of a row of buildings. A building has a view of the sunset if it is taller than every building to its right. Your task is to count how many buildings have a view of the sunset.
Formally, given an array \(h_1, h_2, \dots, h_N\) representing the heights of the buildings (from left to right), a building at index \(i\) has a sunset view if and only if \(h_i > \max(h_{i+1}, h_{i+2}, \dots, h_N)\). The rightmost building always has a sunset view.
Note that if there are no buildings, the answer is 0.
inputFormat
The input is given via stdin and has the following format:
- The first line contains a single integer \(N\) (which can be 0) representing the number of buildings.
- If \(N > 0\), the second line contains \(N\) space-separated integers representing the heights of the buildings.
outputFormat
Output a single integer to stdout — the number of buildings that have a view of the sunset.
## sample0
0