#P9147. 签到题

    ID: 9142 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>动态规划 DP贪心洛谷原创O2优化洛谷月赛

签到题

Background

The famous "Data Deletion" is someone who loves traveling! On this day, he arrived in the mysterious country of ZYL.

When entering customs, he was asked a problem. If he answered correctly, he could successfully reach ZY, the capital of ZYL! As the mighty "Data Deletion", he actually spent 1023310^{-233} seconds to come up with a solution. It was really a bit hard! So he decided to use it to test you.

Problem Description

Given a sequence aa of length nn, it is guaranteed that aia_i are positive integers. You need to choose a position ii and change aia_i to any integer. Maximize the length of the longest strictly increasing substring.

A strictly increasing substring means selecting several consecutive numbers from the sequence such that each later number is greater than the previous one (it cannot be equal to or smaller than the previous one).

For example, in the sequence [1,4,2,3,5][1,4,2,3,5], the subsequence [2,3,5][2,3,5] is a strictly increasing substring, while [4,2,3][4,2,3] (not increasing) and [1,2,3][1,2,3] (not consecutive) are not.

Input Format

The first line contains a positive integer nn, representing the length of the sequence.

The second line contains nn positive integers a1,a2,,ana_1, a_2, \ldots, a_n, representing the sequence aa.

Output Format

Output one line with one integer, representing the maximum possible length of the longest strictly increasing substring after the modification.

5
1 4 2 2 3

3

5
1 2 3 2 1

4

5
1 2 3 1 5

5

6
8 2 3 1 4 5

4

6
7 2 9 4 5 6

5

Hint

[Sample Explanation #1]

For sample #1, we can change the third position in the sequence [1,4,2,2,3][1,4,2,2,3] to 55, obtaining the new sequence [1,4,5,2,3][1,4,5,2,3]. The longest strictly increasing substring of this sequence is [1,4,5][1,4,5], with length 33.

It is easy to prove that there is no modification plan that makes the length of the longest strictly increasing substring greater than 33.


[Sample Explanation #4]

For sample #4, we can change the third position in the sequence [8,2,3,1,4,5][8,2,3,1,4,5] to 00, obtaining the new sequence [8,2,0,1,4,5][8,2,0,1,4,5]. The longest strictly increasing substring of this sequence is [0,1,4,5][0,1,4,5], with length 44.

It is easy to prove that there is no modification plan that makes the length of the longest strictly increasing substring greater than 44.


[Constraints]

For the first 20%20\% of the testdata, n5n \le 5, ai5a_i \le 5.
For the first 40%40\% of the testdata, n10n \le 10, ai10a_i \le 10.
For the first 70%70\% of the testdata, n300n \le 300.
For 100%100\% of the testdata, 1n1061 \le n \le {10}^6, 1ai1091 \le a_i \le {10}^9.

Translated by ChatGPT 5