| UTPC Contest 10-11-24 Div. 1 (Advanced) |
|---|
| Закончено |
Sierra lives in the mountains where it occasionally rains egg yolk. During these storms, yolk pools in the valleys between mountain peaks. Sierra is curious about these pools and would like to know the total volume of the pool with the highest surface elevation.
The topology of the mountain range can be represented by $$$n$$$ integers, where $$$h_i$$$ describes the elevation of the $$$i$$$th location in this range. Some space above a location is considered "part of a pool" if there exist locations to the left and the right of the space with higher or equal elevations. A pool's surface height is defined by the minimum elevation of its immediate neighbors. In cases where there are ties, return the sum of the volumes of all highest pools.
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of locations in the range.
The next line contains the array $$$h_1, h_2, \dots, h_n$$$ ($$$1 \leq h_i \leq 10^9$$$) — the heights of the locations in the range.
Output the volume of the highest pool. If there are multiple pools at the same height, print the sum of their volumes.
81 4 8 2 2 8 1 7
12
There are two pools in the input: one above locations 4 and 5 at a height of 8, and one above location 7 with a height of 7. The first pool is higher, and it has a volume of 12.
| Название |
|---|


