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

[USACO10OPEN] 山峰暸望 Mountain Watching S

Description

One day, Bessie looked at the distant mountain range and wondered, "Which mountain is the widest?"

Bessie managed to measure the heights hih_i at NN positions (1N1051 \leq N \leq 10^5, 1hi1091 \leq h_i \leq 10^9). A mountain is defined as a subsequence whose heights first do not decrease, and then do not increase. The mountains at the edges of the view will only increase or only decrease in height. The width of a mountain is defined as the number of positions included in that mountain.

Here is an example:

           *******                   *
          *********                 ***
          **********               *****
          ***********           *********               *
*      *****************       ***********             *** *
**    *******************     *************   * *     *******      *
**********************************************************************
3211112333677777776543332111112344456765432111212111112343232111111211
aaaaaa                   ccccccccccccccccccccc eeeeeee    ggggggggg
  bbbbbbbbbbbbbbbbbbbbbbbbbbbb             ddddd ffffffffff  hhhhhhhhh

Each mountain has been labeled with a letter. Here, mountain b has the largest width, which is 2828.

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,12, 3, 5, 4, 1. Other mountains include 3,23, 2 and 1,61, 6.


Hint

If you know the highest part of a mountain (that is, the peak), you will find that it is very easy to determine the width of the mountain.

Translated by ChatGPT 5