#C3574. Trapping Rain Water

    ID: 47016 Type: Default 1000ms 256MiB

Trapping Rain Water

Trapping Rain Water

Given an array of non-negative integers representing the height of bars in a histogram, compute the maximum volume of water that can be trapped after raining. The water trapped at each index i is determined by the formula \(w_i = \min(L_i, R_i) - H_i\), where \(L_i\) is the maximum height to the left of i and \(R_i\) is the maximum height to the right of i. Note that if an index does not have bars on one side, then no water can be trapped at that position.

Your task is to calculate the sum of water trapped across all indices.

inputFormat

The input is provided via standard input (stdin) as a single line containing space-separated integers representing the heights of the bars. If the line is empty, consider it as an empty list.

outputFormat

Output a single integer (to stdout) representing the maximum volume of water that can be trapped.

## sample
0 1 0 2 1 0 1 3 2 1 2 1
6