#K80667. Total Views
Total Views
Total Views
You are given a line of people, each with a certain height. For each person (except the first one), you need to compute the number of people they can see to their left. A person at position i can see a person at position j (where j < i) if and only if the height of the person at j is greater than or equal to the height of the person at i. However, as soon as a person fails this condition, their view is blocked and no one further to the left can be seen by person i.
In other words, for every person at index i (with 1-based indexing starting from 2), count the number of consecutive persons immediately to the left such that for each person at position j (where i-1 ≥ j ≥ 1), the following holds:
\( h_j \ge h_i \)
The total views is the sum of these counts over all people. Your task is to compute and output this total number.
inputFormat
The first line contains an integer n
representing the number of people.
The second line contains n
space-separated integers, where each integer represents the height of a person in the line.
outputFormat
Output a single integer that is the total number of views as described above.
## sample5
4 3 5 1 2
4
</p>