#K41857. Sunset Views
Sunset Views
Sunset Views
You are given a sequence of N building heights. A building can view the sunset if and only if there is no building to its left that is taller than or equal to it. Formally, a building at index i (1-indexed) can view the sunset if for every index j such that 1 ≤ j < i, the height of building j is less than the height of building i.
Your task is to determine the number of buildings that can view the sunset.
Note: The buildings are given in the order from left to right.
The condition for a building at position i to see the sunset can be mathematically expressed as:
[
\text{Building}i \text{ sees the sunset if } h_i > \max{1 \leq j < i} (h_j)
]
If there is no building before building i, then it can always see the sunset.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a single integer N denoting the number of buildings.
- The second line contains N space-separated integers, where the i-th integer represents the height of the i-th building.
outputFormat
Output a single integer to standard output (stdout), which is the number of buildings that can view the sunset.
## sample5
4 7 2 5 8
3
</p>