#C1124. Towers with a View

    ID: 40534 Type: Default 1000ms 256MiB

Towers with a View

Towers with a View

In this problem, you are given a sequence of building heights. A building is considered to have a clear view if it is strictly taller than every building to its right. Formally, given a list of integers (a_1, a_2, \dots, a_n), a building at position (i) (with height (a_i)) is counted if (a_i > \max{a_{i+1}, a_{i+2}, \dots, a_n}). The rightmost building always has a clear view by definition. Your task is to compute the number of such buildings. This problem requires efficient processing as the number of buildings can be very large.

inputFormat

The input is given via standard input (stdin). The first line contains a single integer (n) representing the number of buildings. The second line contains (n) space-separated integers, where each integer represents the height of a building.

outputFormat

Output a single integer to standard output (stdout) representing the number of buildings that are taller than all buildings to their right.## sample

5
4 2 7 1 3
2