Knak and the 3D Printer
InterviewTime limit1sMemory limit1024 MB
Given N bar heights of width 1, find the total surface area of the histogram solid, counting the top, bottom, and side faces.
- Level
Easy2 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
One day, Knak received a 3D printer as a gift from an acquaintance. Knak had long been interested in 3D printers and was excited, but could not think of what to make with it. So Knak decided to print a histogram that caught his eye using the 3D printer.
A histogram is a shape in which bars of the same width are placed in a row with no gaps. Knak will print this as a 3D model made of rectangular boxes, each with width and depth and height .
With no money to spare, Knak wants to be extremely frugal. He will leave the inside of the model hollow and use exactly as much material as the surface area. Given the information of the histogram, find the surface area of the 3D model.
Input
The first line contains an integer , the number of bars in the histogram. ()
The second line contains the heights of the bars, , separated by spaces. ()
Output
Print the surface area of the 3D histogram model.