#C13650. Evol: Analyze Buildings for Rainwater Trapping and Material Volume
Evol: Analyze Buildings for Rainwater Trapping and Material Volume
Evol: Analyze Buildings for Rainwater Trapping and Material Volume
Given a sequence of building heights, calculate two values:
- The maximum amount of rainwater that can be trapped between the buildings, computed using the well-known water trapping method. The water trapped at a position is given by \(\max(0, \min(\text{leftMax}, \text{rightMax}) - \text{height})\).
- The total volume of building material used, which is simply the sum of the building heights.
The input is provided via standard input. The first line contains an integer \(n\) representing the number of buildings. If \(n > 0\), the second line contains \(n\) space-separated integers specifying the heights of the buildings.
Output two integers separated by a space: the maximum rainwater trapped and the total building material volume, respectively.
inputFormat
The first line of input contains an integer n ((n \geq 0)). If n is positive, the second line contains n integers representing the heights of the buildings separated by spaces.
outputFormat
Output two integers separated by a space. The first integer is the maximum volume of rainwater that can be trapped, and the second integer is the total volume of building material used.## sample
0
0 0