| Author: | Pavel Mesenev | Time limit: | 2 sec | |
| Input file: | Standard input | Memory limit: | 256 Mb | |
| Output file: | Standard output |
You are given n non-negative integers h0, h1, …, hn − 1 representing an elevation map, each bar having width 1. Compute how much water it can trap after raining.
The first line contains one integer n. The second line contains n space-separated integers h0… hn − 1.
Print one integer — the total trapped water.
1 ≤ n ≤ 2 ⋅ 105
0 ≤ hi ≤ 106
| No. | Standard input | Standard output |
|---|---|---|
| 1 |
|
|
| 2 |
|
|
| 3 |
|
|