Question
The Monsoon Gorge Overflow
A geologist is surveying a canyon whose cross-section is described by
Calculate the total units of water trapped across the entire canyon after the rain.
Input
The first line contains KaTeX can only parse string typed expression. The second line contains KaTeX can only parse string typed expression space-separated non-negative integers — the elevation map.
Output
A single integer — the total water trapped.
Example
Example 1:
Input
Example 2:
Input
Input
12
0 1 0 2 1 0 1 3 2 1 2 1Output6Example 2:
Input
4
4 2 0 3Output4