标签:
//实现和上面讲得有点差异,但是原理一样
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 1E5 + 10;
int a[maxn],b[maxn],c[maxn],n;
int main(){
scanf("%d",&n);
for(int i = 1 ; i <= n ; ++i){
scanf("%d",&a[i]);
}
b[1] = 1;
for(int i = 2 ; i <= n ; ++i){
if(a[i] > a[i - 1]) b[i] = b[i - 1] + 1;
else b[i] = 1;
}
c[n] = 1;
for(int i = n ; i >= 2 ; --i){
if(a[i] > a[i - 1]) c[i - 1] = c[i] + 1;
else c[i - 1] = 1;
}
int ans = c[1]+1;
for(int i = 2 ; i < n ; ++i){
if(a[i - 1] < a[i] && a[i] < a[i + 1]){
ans = min(n,max(ans,b[i] + c[i]) );
}
if(a[i - 1] + 1 < a[i + 1])
ans = max(ans , b[i - 1] + c[i + 1] + 1);
}
ans = min(n,max(ans,b[n]+1));
printf("%d\n",ans);
return 0;
}
[2016-04-13][codeforces][447][C][DZY Loves Sequences]
标签:
原文地址:http://www.cnblogs.com/qhy285571052/p/790caea5d448a73bb240c7c81dcac87f.html