#P1317. 低洼地

低洼地

Description

A sequence of numbers represents the ground profile’s elevation changes. The height values are integers, and adjacent heights are connected by straight line segments. Find and count how many low-lying depressions could hold water.

As shown: the elevation changes are [0,1,0,2,1,2,0,0,2,0][0,1,0,2,1,2,0,0,2,0].

Input Format

Two lines.

  • Line 1: nn, the number of heights.
  • Line 2: nn integers giving the ground profile heights, with the first and last equal to 00. (3n10000,0(3 \le n \le 10000, 0 \le height 1000)\le 1000).

Output Format

A single integer: the number of depressions that can potentially hold water.

10
0 1 0 2 1 2 0 0 2 0

3

Hint

Translated by ChatGPT 5