3D Surface Area
medium⏱ 15 mintypescriptchallengesproblem-solving-intermediate-
Caso de ejemplo — tu programa lee de stdin e imprime en stdout.
2D grid A[i][j] = height (cubes) at cell (i,j). Calculate total surface area of the 3D shape.
Formula: Top + Bottom + 4 sides. For each cell: top=1, bottom=1, each side = max(0, height - neighbor_height) if neighbor exists, else = height. Sum all faces.
Example: Grid [[1,3,4],[2,2,3],[1,2,4]] → Calculate exposed faces for each cell and sum.
Formato de entrada
First line: H W (space-separated). Next H lines: W space-separated integers each.
Formato de salida
A single integer: the total surface area.
Restricciones
1 ≤ H, W ≤ 100, 0 ≤ A[i][j] ≤ 100