Problems > Dry Spells

Dry Spells

Difficulty: 1000 3000 ms 128 MB

implementation

Daily rainfall amounts are given. A dry spell is a maximal run of ≥ 3 consecutive zero-rain days. Count the dry spells.

Input: the first line has N; the second line has the N rainfall values.

Output: the number of dry spells.

Constraints:

  • 1 ≤ N ≤ 105
  • 0 ≤ rain ≤ 30

Sample Tests

Input 1
8
5 0 0 0 2 0 0 1
Output 1
1
Input 2
3
0 0 0
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.