#K81847. Calculate Total Area of Buildings
Calculate Total Area of Buildings
Calculate Total Area of Buildings
You are given the heights of a series of contiguous buildings, each of width 1 unit. Your task is to compute the total area covered by these buildings when viewed from the side. The area is calculated by summing up the heights of all buildings.
The formula for the total area is given by: $$A = \sum_{i=1}^{n} h_i$$, where \(h_i\) represents the height of the \(i\)-th building and \(n\) is the total number of buildings.
All building heights are non-negative integers.
inputFormat
The input consists of two lines:
- The first line contains an integer \(n\) (\(1 \leq n \leq 10^5\)), which is the number of buildings.
- The second line contains \(n\) space-separated non-negative integers representing the heights of the buildings. Each height \(h_i\) satisfies \(0 \leq h_i \leq 10^4\).
outputFormat
Output a single integer, which is the total area covered by the buildings.
## sample3
2 1 3
6
</p>