P1893 [USACO10OPEN] Mountain Watching S

Description

One day, Bessie gazed at the distant mountains and wondered, "Which mountain is the widest?" Bessie managed to measure the heights $h_i$ at $N$ positions ($1 \leq N \leq 10^4$, $1 \leq h_i \leq 10^9$). A mountain is defined as a contiguous subsequence whose heights first do not decrease and then do not increase. Mountains at the edges of the view may only increase or only decrease in height. The width of a mountain is defined as the number of positions it contains. Here is an example: ```plain ******* * ********* *** ********** ***** *********** ********* * * ***************** *********** *** * ** ******************* ************* * * ******* * ********************************************************************** 3211112333677777776543332111112344456765432111212111112343232111111211 aaaaaa ccccccccccccccccccccc eeeeeee ggggggggg bbbbbbbbbbbbbbbbbbbbbbbbbbbb ddddd ffffffffff hhhhhhhhh ``` Each mountain has been labeled with letters. Here, the mountain labeled `b` has the maximum width, which is 28.

Input Format

The first line contains an integer $N$. The next $N$ lines each contain an integer $h_i$.

Output Format

Output the width of the widest mountain.

Explanation/Hint

Sample explanation: At the widest mountain, the measured heights are 2, 3, 5, 4, 1. Other mountains include 3, 2 and 1, 6. --- Hint: If you know the highest part of a mountain (the peak), you will find it easy to determine its width. Translated by ChatGPT 5