C - DZY Loves Sequences

DZY has a sequence a, consisting of n integers.

We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.

Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.

You only need to output the length of the subsegment you find.

Input

The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

In a single line print the answer to the problem — the maximum length of the required subsegment.

Example

Input
67 2 3 1 5 6
Output
5

Note

You can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4.

题目意思是,给出一个序列,只能改变一个数的值,使最长上升子序列的长度最长.

这题其实挺水.我们设f[i]为第i个数左边的最长上升子序列的长度,g[i]为第i个数右边的最长上升子序列的长度,

然后在满足a[i-1]+1<=a[i+1]-1的情况下,求一下max(g[i]+f[i]+1)就行了.然后居然WA了......

后来发现,还有种情况没发现,就是以i结尾或开头的子序列,也有可能是最优的→_→

 #include<cstdio>
 #include<cstring>
 #include<algorithm>
 using namespace std;
 ],f1[],f2[],n,ans;
 int read(){
     ,f=; char ch=getchar();
     '){if (ch=='-') f=-f; ch=getchar();}
     +ch-',ch=getchar();
     return x*f;
 }
 int main(){
     n=read(); ; i<=n; i++) a[i]=read();
     ){puts(;}
     ){puts(;}
     f1[]=,f1[]=;
     ; i<=n; i++) ]>a[i-]) f1[i]=f1[i-]+; ;
     f2[n]=,f2[n-]=;
     ; i>=; i--) ]>a[i+]) f2[i]=f2[i+]+; ;
     ans=max(ans,f2[]+); ans=max(ans,f1[n]+);
     ; i<n; i++){
         ]+<=a[i+]-) ans=max(ans,f1[i]+f2[i]+);
         ans=max(ans,f1[i]+);
         ans=max(ans,f2[i]+);
     }
     printf("%d",ans);
     ;
 }

最新文章

  1. app分享时判断手机是否已安装微信或QQ客户端
  2. storyboard自动布局时,代码修改 constraint 的值,没有反应
  3. WPF-拖动面板移动窗口&amp;设置窗口状态
  4. C Memory Layout C语言中的内存布局
  5. Linux驱动设计—— 中断与时钟@request_irq参数详解
  6. delphi 基础之三 编写和调用dll文件
  7. innerHTML与innerText的PK
  8. [Angular 2] Create Angular 2 Porject with Angular CLI
  9. nosql和关系型数据库比较?
  10. doubango(2)--底层协议栈结构分析
  11. 初学Python(八)——迭代
  12. 在centos6编译安装http-2.4
  13. ruby技巧001:求md5散列
  14. 使用LR编写windows sockets协议xml报文格式脚本实战
  15. Windows应用程序组成及编程步骤
  16. 【Golang】如何统一处理HTTP请求中的异常捕获
  17. BZOJ4385[POI2015]Wilcze doły——单调队列+双指针
  18. 【从0到1学javascript】javascript数据结构----数组
  19. 在SpringMVC中使用@RequestBody注解处理json时,报出HTTP Status 415的解决方案
  20. TeeChart入门

热门文章

  1. python学习 day06打卡
  2. 【Selenium2】【selenium之 定位以及切换frame(iframe)】
  3. Mysql 函数使用记录(一)——DATEDIFF、CONCAT
  4. Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland dfs
  5. ubuntu 14.04 安装pip
  6. CentOS7 使用firewalld打开关闭防火墙以及端口
  7. 《剑指offer》第五十一题(数组中的逆序对)
  8. DRF框架固定配置
  9. VNPY思维导图架构
  10. gdb 的 symbos 加载详情(set verbose on)