Code
The highlighted line runs next. The pill shows the live values in the running call.
Cost
Work done so far, and how the four solutions compare
Elevation map
Blue is water found so far; +n is water above a bar
The highlighted line runs next. The pill shows the live values in the running call.
Work done so far, and how the four solutions compare
Blue is water found so far; +n is water above a bar
Keyboard: ← → step, Space play or pause. 1 to 12 heights, whole numbers from 0 to 9. With the real limits (n ≤ 20,000, heights ≤ 100,000) the total stays under 2·10⁹, which fits in a 32-bit int in Java and C++.