#P6510. 奶牛排队

    ID: 5505 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>单调队列NOI 导刊O2优化分治RMQ

奶牛排队

Description

Under Aunt Xiong’s lead, the cows form a straight line.

Obviously, different cows may have different heights.

Now the cows want to know: if we pick some consecutive cows, requiring that the leftmost cow AA is the shortest, the rightmost cow BB is the tallest, and cow BB is taller than cow AA. If there are cows in the middle, then their heights must not be the same as cows AA or BB. What is the maximum number of cows that can be chosen?

The cows’ heights are given from left to right. Please output the maximum number of cows that satisfies the conditions (the answer may be 00 or 22, but will not be 11).

Input Format

The first line contains a positive integer NN, the number of cows.

The next NN lines each contain a positive integer, where from top to bottom they give the heights hih_i of the cows from left to right.

Output Format

Output one integer in a single line, the maximum number of cows.

5
1
2
3
4
1
4

Hint

Sample Explanation

Choose cows from the 11st to the 44th; this satisfies the conditions and is the maximum.

Constraints

For all testdata, 2N1052 \le N \le 10^5, 1hi<2311 \le h_i <2^{31}.

Translated by ChatGPT 5