#STK0000078. Vườn trên mái (Rooftop Garden)
Vườn trên mái (Rooftop Garden)
Rooftop Garden
Source: Baekjoon Online Judge
Version: Phuoc Hung OJ Extended
Problem Statement
There are buildings arranged from left to right. The owner of building can see the rooftops of consecutive buildings to the right until the first building whose height is greater than or equal to building . Compute the total number of rooftops visible to all owners.
Input
The first line contains . Each of the next lines contains one building height, in left-to-right order.
Output
Print one integer: the total number of visible owner-rooftop pairs described above.
Subtasks
- Subtask 1 (30 points): ; all other conditions are unchanged.
- Subtask 2 (70 points): , .
Examples
Input
6
10
3
7
4
12
2
Output
5
Explanation
Consider the buildings from left to right:
- Height sees the rooftops of heights . Height is the first building with height at least , so the view stops before it: contribution .
- Height immediately meets height , so it sees no rooftop: contribution .
- Height sees height , then height blocks the view: contribution .
- Height is immediately blocked by height : contribution .
- Height sees the final rooftop of height : contribution .
- The last building has nothing to its right: contribution .
The total is , so the output is 5.