#K4151. Longest Non-Decreasing Period

    ID: 26881 Type: Default 1000ms 256MiB

Longest Non-Decreasing Period

Longest Non-Decreasing Period

You are given the number of days n and a list of daily stock prices. Your task is to find the length of the longest contiguous period during which the stock prices never decrease.

More formally, given an array of prices a1, a2, ..., an, you need to determine the maximum length L such that there exists an index i with 1 ≤ i ≤ n-L+1 and for every j with i+1 ≤ j ≤ i+L-1, the condition aj \geq aj-1 holds. The answer should be output as a single integer representing the length of this period.

Note: If there is only one day, the output is 1.

In LaTeX, the non-decreasing condition can be written as:

$$a_{j} \geq a_{j-1}, \quad \text{for } i+1 \leq j \leq i+L-1.$$

inputFormat

The first line of input contains an integer n specifying the number of days.

The second line contains n space-separated integers representing the daily stock prices.

For example:

6
100 100 105 103 105 107

outputFormat

Output a single integer representing the length of the longest contiguous period of non-decreasing stock prices.

For the sample above, the output is 3 because the longest non-decreasing period is from day 1 to day 3: 100, 100, 105.

## sample
6
100 100 105 103 105 107
3