#P1893. [USACO10OPEN] 山峰暸望 Mountain Watching S

[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 hih_i at NN positions (1N1041 \leq N \leq 10^4, 1hi1091 \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:

           *******                   *
          *********                 ***
          **********               *****
          ***********           *********               *
*      *****************       ***********             *** *
**    *******************     *************   * *     *******      *
**********************************************************************
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 NN.

The next NN lines each contain an integer hih_i.

Output Format

Output the width of the widest mountain.

7
3
2
3
5
4
1
6

5

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