#C3558. Highest Peak in Mountains

    ID: 46998 Type: Default 1000ms 256MiB

Highest Peak in Mountains

Highest Peak in Mountains

Given a list of integers representing mountain heights, your task is to find the height of the highest peak. A peak is defined as an element that is not lower than its neighbors. Specifically:

  • The first element is a peak if it is not lower than the second element.
  • The last element is a peak if it is not lower than the penultimate element.
  • Any middle element is a peak if it is not lower than both its adjacent elements.

If the list contains only one element, that element is considered the peak. Output the height of the highest peak.

The mathematical condition for a peak element at index i (with 0-based indexing) is:

$$ \text{if } i = 0: m_0 \ge m_1, \quad \text{if } 0 < i

inputFormat

The first line contains a single integer n, the number of mountain heights. The second line contains n space-separated integers representing the heights.

outputFormat

Output a single integer: the height of the highest peak in the list.## sample

1
10
10