TopcoderArchive
SRM24 Sep 2008
SRM 419

ColumnDiagramPerimeter

Problem statement, definition, constraints, and public examples.

Problem Statement

A column diagram is composed of n consecutive columns arranged in a horizontal row. Each column has a width of 1, and the base of each column is on the x-axis. The heights of the columns are given in the int[] a, where a[i] is the height of the i-th column. The picture below shows an example of a column diagram:

Return the perimeter of the given column diagram.

Definition

Class:
ColumnDiagramPerimeter
Method:
getPerimiter
Parameters:
int[]
Returns:
int
Method signature:
int getPerimiter(int[] a)
(be sure your method is public)

Constraints

  • a will contain between 1 and 50 elements, inclusive.
  • Each element of a will be between 1 and 50, inclusive.

Examples

  1. {2,3,5,6,1}
    Returns: 22
    This column diagram is shown on the picture in the problem statement.
  2. {3,2,1}
    Returns: 12
  3. {2,2}
    Returns: 8
  4. {1,2,1}
    Returns: 10
  5. {1,2,3}
    Returns: 12
Back to all problems