#C8379. Longest Decreasing Subarray from a Peak

    ID: 52354 Type: Default 1000ms 256MiB

Longest Decreasing Subarray from a Peak

Longest Decreasing Subarray from a Peak

You are given a sequence of integers representing the elevation values of a mountain range. A peak is defined as an element that is strictly greater than its immediate neighbors. For the first and last elements, only one neighbor exists, so they are considered a peak if they are greater than that neighbor.

Your task is to find the longest contiguous subarray that starts at a peak and continues as long as the subsequent elements are strictly decreasing. Formally, given an array of length \(n\) with elements \(heights[0], heights[1], \ldots, heights[n-1]\), you need to determine the maximum length \(L\) such that there exists an index \(i\) where \(heights[i]\) is a peak and for each \(j\) from \(i\) to \(i+L-2\), the condition \(heights[j] > heights[j+1]\) holds.

If no decreasing sequence is found after a peak, the length is considered to be 1 (the peak itself).

inputFormat

The input is given via standard input (stdin) with the following format:

  1. The first line contains a single integer \(n\) (\(1 \le n \le 10^5\)), representing the number of elements in the array.
  2. The second line contains \(n\) space-separated integers, representing the elevation values.

outputFormat

The output is a single integer (written to standard output, stdout) representing the length of the longest decreasing contiguous subarray starting at a peak.

## sample
6
5 3 6 7 4 2
3

</p>