#K36532. Counting Sunlit Buildings
Counting Sunlit Buildings
Counting Sunlit Buildings
Given a sequence of building heights, your task is to count the number of sunlit buildings. A building is considered sunlit if no building to its left is taller. More formally, the first building is always sunlit, and for each subsequent building, it is sunlit only if its height is greater than the maximum height of all buildings to its left. In mathematical terms, if the heights are given by \(h_1, h_2, \ldots, h_n\), then building \(i\) is sunlit if \(h_i > \max\{h_1, h_2, \ldots, h_{i-1}\}\).
For example, given the list of heights [3, 6, 7, 2, 9], the sunlit buildings are those of heights 3, 6, 7, and 9, so the answer is 4.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a single integer \(n\) representing the number of buildings.
- The second line contains \(n\) space-separated integers representing the heights of the buildings.
outputFormat
Output a single integer — the number of sunlit buildings. The output should be written to standard output (stdout).
## sample5
3 6 7 2 9
4
</p>