#P1318. 积水面积
积水面积
Description
A sequence of positive integers represents the heights of columns formed by stacking cubes. If a height value is , it means unit cubes are stacked (as in the figure, ). Find all positions where water can be trapped (the blue parts in the figure) and compute the total trapped area (this is the cross-sectional area in the figure. Each unit cube position corresponds to 1 unit area).
Example: the column heights change as 0 1 0 2 1 2 0 0 2 0.

The blue parts in the figure are the trapped area, totaling unit areas.
Input Format
Two lines. The first line contains , the number of values (). The second line contains consecutive integers giving the heights of the stacked cubes in order, with the guarantee that the first and last values are .
Output Format
A single number: the total trapped area.
10
0 1 0 2 1 2 0 0 2 0
6
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号