#P9147. Maximize Longest Strictly Increasing Subarray

    ID: 22304 Type: Default 1000ms 256MiB

Maximize Longest Strictly Increasing Subarray

Maximize Longest Strictly Increasing Subarray

Given a sequence \(a\) of length \(n\) with positive integers, you are allowed to choose exactly one position \(i\) (1-indexed) and modify \(a_i\) to any integer. Your task is to maximize the length of the longest strictly increasing contiguous subarray after performing the modification.

A strictly increasing contiguous subarray is a sequence of consecutive elements from \(a\), where each element is strictly greater than the previous one. For example, in the sequence \([1, 4, 2, 3, 5]\), the subarray \([2, 3, 5]\) is strictly increasing, while \([4, 2, 3]\) (not increasing) and \([1, 2, 3]\) (not contiguous) are not.

inputFormat

The input consists of two lines:

  • The first line contains an integer \(n\) (\(1 \le n \le 10^5\)), the length of the sequence.
  • The second line contains \(n\) positive integers \(a_1, a_2, \ldots, a_n\).

outputFormat

Output a single integer - the maximum length of the longest strictly increasing contiguous subarray that can be obtained after modifying exactly one element.

sample

5
1 4 2 3 5
4

</p>