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);
     ;
 }

[CodeForces - 447C] C - DZY Loves Sequences的更多相关文章

  1. Codeforces 447 C DZY Loves Sequences【DP】

    题意:给出一列数,在这个序列里面找到一个连续的严格上升的子串,现在可以任意修改序列里面的一个数,问得到的子串最长是多少 看的题解,自己没有想出来 假设修改的是a[i],那么有三种情况, 1.a[i]& ...

  2. 【Codeforces 446A】DZY Loves Sequences

    [链接] 我是链接,点我呀:) [题意] 让你找一段连续的区间 使得这一段区间最多修改一个数字就能变成严格上升的区间. 问你这个区间的最长长度 [题解] dp[0][i]表示以i为结尾的最长严格上升长 ...

  3. Codeforces 447C - DZY Loves Sequences

    447C - DZY Loves Sequences 思路:dp 代码: #include<bits/stdc++.h> using namespace std; #define ll l ...

  4. codeforces#FF DIV2C题DZY Loves Sequences(DP)

    题目地址:http://codeforces.com/contest/447/problem/C C. DZY Loves Sequences time limit per test 1 second ...

  5. Codeforces Round #FF (Div. 1) A. DZY Loves Sequences 动态规划

    A. DZY Loves Sequences 题目连接: http://www.codeforces.com/contest/446/problem/A Description DZY has a s ...

  6. DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences

    题目传送门 /* DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生: 1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + ...

  7. Codeforces Round #FF (Div. 2):C. DZY Loves Sequences

    C. DZY Loves Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. Codeforces Round #FF 446A DZY Loves Sequences

    预处理出每一个数字能够向后延伸多少,然后尝试将两段拼起来. C. DZY Loves Sequences time limit per test 1 second memory limit per t ...

  9. cf446A DZY Loves Sequences

    A. DZY Loves Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...

随机推荐

  1. SAP成本核算说明

    SAP成本核算说明 <SAP财务管控——财务总监背后的管理大师>京东有售. > SAP成本核算说明 说明: 1.    原材料采用移动平均价核算:产成品采用计划(标准)成本核算: 2 ...

  2. 使用v-for循环写入html内容,每一项的数据的写入

    项目使用vue.js,在写某个dialog页面时,需要循环后台的数据(班级,班级学生名单,已选学生名单,发布时间,截止时间,答案显示等). 遇到的问题:循环绑定的值是相同的,而且改动一个值,其他ite ...

  3. Codeforces 600E. Lomsat gelral(Dsu on tree学习)

    题目链接:http://codeforces.com/problemset/problem/600/E n个点的有根树,以1为根,每个点有一种颜色.我们称一种颜色占领了一个子树当且仅当没有其他颜色在这 ...

  4. 【BZOJ】3572: [Hnoi2014]世界树

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3572 算是细节题了吧.. 构出虚树,考虑z正反DP两次求出虚树中每个点最近的议事处是哪一个 ...

  5. 下载安装Android sdk tools

    安装java: https://www.cnblogs.com/sea-stream/p/5815957.html 下载地址:https://www.androiddevtools.cn/ 选择版本 ...

  6. Selenium 页面自动化测试 面试 问题汇总

    1.   专业技术 在学习完Selenium的大部分接口或者方法之后,你可能会去面试自动化测试,主要是Selenium的自动化测试.下面这些问题总结,可能会对你有所帮助. 什么是Selenium? S ...

  7. CentOS7下搭建LAMP+FreeRadius+Daloradius Web管理

    注意:本文所有命令均在root命令下执行. freeradius服务官网:http://freeradius.org/ daloradius Web管理页面官网:https://sourceforge ...

  8. idea关于热部署插件JRebel的使用教程

    1. idea安装JRebel热部署插件 在1处输入jrebel然后在3处点击install安装按钮就可以了,安装好以后如下图: 2. 激活JRebel help -> JRebel -> ...

  9. Spark之standalone模式

    standalone hdfs:namenode是主节点进程,datanode是从节点进程 yarn:resourcemanager是主节点进程,nodemanager是从节点进程 hdfs和yarn ...

  10. linux基础02-bash特性

    Linux的行结束符是:[$] Windows的行结束符是:[$+回车] 目录管理:ls.cd.pwd.mkdir.rmdir.tree 文件管理:touch.stat.file.rm.cp.mv.n ...