Remove One Element(贪心)
You are given an array aa consisting of nn integers.
You can remove at most one element from this array. Thus, the final length of the array is n?1n?1 or nn.
Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array.
Recall that the contiguous subarray aa with indices from ll to rr is a[l…r]=al,al+1,…,ara[l…r]=al,al+1,…,ar. The subarray a[l…r]a[l…r] is called strictly increasing if al<al+1<?<aral<al+1<?<ar.
Input
The first line of the input contains one integer nn (2≤n≤2?1052≤n≤2?105) — the number of elements in aa.
The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109), where aiai is the ii-th element of aa.
Output
Print one integer — the maximum possible length of the strictly increasing contiguous subarray of the array aa after removing at most one element.
Examples
Input
5
1 2 5 3 4
Output
4
Input
2
1 2
Output
2
Input
7
6 5 4 3 2 4 3
Output
2
Note
In the first example, you can delete a3=5a3=5. Then the resulting array will be equal to [1,2,3,4][1,2,3,4] and the length of its largest increasing subarray will be equal to 44.
思路:最多刪除一個,那么我們就記錄這一個數(shù)字前一個數(shù)字和后一個數(shù)字的最長連續(xù)序列。然后貪心的取最大值。事先用dfs預(yù)處理好每一個數(shù)字最遠可以到達哪里。具體看代碼。
代碼如下:
努力加油a啊,(o)/~
總結(jié)
以上是生活随笔為你收集整理的Remove One Element(贪心)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Yet Another Broken K
- 下一篇: Nearest Opposite Par