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. 1.Jenkins 在windows下的安装与配置

    1. 安装Jenkins 1.war包安装:启动Jenkins命令,打开cmd至Jenkins安装目录下,运行命令 java -jar jenkins.war 如果改变默认端口,则指定端口例如端口号1 ...

  2. 基于 Python 和 Pandas 的数据分析(4) --- 建立数据集

    这一节我想对使用 Python 和 Pandas 的数据分析做一些扩展. 假设我们是亿万富翁, 我们会想要多元化地进行投资, 比如股票, 分红, 金融市场等, 那么现在我们要聚焦房地产市场, 做一些这 ...

  3. javascript 创建video元素

    <!DOCTYPE html> <html> <body> <h3>演示如何创建 VIDEO 元素</h3> <p>请点击按钮来 ...

  4. pandas计数 value_counts()

    来自:曹骥 在pandas里面常用value_counts确认数据出现的频率. 1. Series 情况下: pandas 的 value_counts() 函数可以对Series里面的每个值进行计数 ...

  5. jmeter5.0之源码导入 IntelliJ IDEA

    IDEA 编译 Jmeter 1.下载并解压 jmeter 源码 http://archive.apache.org/dist/jmeter/source/ 下载源码后解压『Jmeter』,我这边下载 ...

  6. C++.构造函数(超出范围)_01

    环境:Win7x64.Qt5.3.2 MSVC2010 OpenGL.vs2010 1.ZC:在 构造函数 中,基类访问子类的成员 会报内存错误,如果访问的是 基本类型的话(如int) 可能还不会出错 ...

  7. vue模板编译

    Vue 的模板编译是在 $mount 的过程中进行的,在 $mount 的时候执行了 compile 方法来将 template 里的内容转换成真正的 HTML 代码. complie 最终生成 re ...

  8. 学习笔记36—坚果云 | Papership或Zotero使用webDAV验证服务器不成功怎么办?

    很多人都喜欢用坚果云作为Zotero的第三方云盘,从而无限扩展Zotero的存储空间.可是大家在Papership或zotero客户端中验证坚果云webDAV服务器时,会出现验证不成功的问题,相信这个 ...

  9. QT5 解决QSqlDatabase: QMYSQL driver not loaded 问题

    QT版本 Qt 5.12.0 MySQL版本 8.0.13 转到MySQL的安装目录 G:\mysql-8.0.13-winx64\mysql-8.0.13-winx64\lib 将安装目录下的两个文 ...

  10. 猫眼电影爬取(一):requests+正则,并将数据存储到mysql数据库

    前面讲了如何通过pymysql操作数据库,这次写一个爬虫来提取信息,并将数据存储到mysql数据库 1.爬取目标 爬取猫眼电影TOP100榜单 要提取的信息包括:电影排名.电影名称.上映时间.分数 2 ...