#K2096. Longest Contiguous Subarray with One Removal

    ID: 24660 Type: Default 1000ms 256MiB

Longest Contiguous Subarray with One Removal

Longest Contiguous Subarray with One Removal

You are given an array of integers. Your task is to find the length of the longest contiguous subarray such that after removing at most one element from this subarray, the remaining integers are in non-decreasing order.

In other words, you need to determine the maximum length of a subarray (i.e. a consecutive segment of the array) for which there exists an index (or no removal at all) such that if you remove the element at that index, the rest of the subarray satisfies:

$$a_1 \leq a_2 \leq \cdots \leq a_{k-1} \leq a_{k+1} \leq \cdots \leq a_m $$

where \(m\) is the length of the subarray before removal and \(k\) is the index of the removed element (if any). If no removal is done, then the subarray itself must be non-decreasing.

inputFormat

The first line contains a single integer \(n\) denoting the number of elements in the array.

The second line contains \(n\) space-separated integers representing the elements of the array.

outputFormat

Output a single integer denoting the length of the longest contiguous subarray that can be made non-decreasing by removing at most one element.

## sample
5
1 2 3 4 5
5

</p>