Codeforces Round #FF (Div. 2):C. DZY Loves Sequences[通俗易懂]

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

standard input

output

standard output

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.

Sample test(s)
Input
6
7 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.

题意就是, 你能够改变字符串中的一个字符。 就出其最长的连续字串

如案列, 7 2 3 1 5 6 —————7 2 3  4 5 6

输出即为5.


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath>

using namespace std;

#define f1(i, n) for(int i=0; i<n; i++)
#define f2(i, m) for(int i=1; i<=m; i++)
#define f3(i, n) for(int i=n; i>=1; i--)
#define f4(i, n) for(int i=1; i<=n; i++)
#define f5(i, n) for(int i=2; i<=n; i++)
#define M 1005

const int INF = 0x3f3f3f3f;
int n, a[100005], b[100005];

int main()
{
    cin>>n;
    f4(i, n)
    cin>>a[i];
    b[1]=1;
    f5(i, n)
    {
        b[i]=1;
        if (a[i]>a[i-1])
            b[i]=b[i-1]+1;
    }
    int ans=-INF;
    f3(i, n)
    {
        if (b[i]==n)
            ans=max(b[i], ans);
        else
            ans=max(ans, b[i]+1);
        if (a[i-b[i]+1]-1>a[i-b[i]-1])
            ans=max(ans,b[i]+b[i-b[i]]);
        if (a[i-b[i]+2]-1>a[i-b[i]])
            ans=max(ans,b[i]+b[i-b[i]]);
    }
    cout<<ans<<endl;
    return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116123.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 计算机的储存容量1kb等于多少byte,1M等于多少字节?

    计算机的储存容量1kb等于多少byte,1M等于多少字节?1M等于多少字节?以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!1M等于多少字节?不是1M等于多少字节,是1MB等于多少字节。字节(Byte/bait/n.[C])是计算机信息技术用于计量存储容量的一种计量单位,也表示一些计算机编程语言中的数据类型和语言字符。字节用符号“B”表示。MB(全称MByte):计算机中…

    2022年5月9日
    79
  • tar 打包的时候如何去掉目录前缀

    tar 打包的时候如何去掉目录前缀文章转载自:freefly的博客,对原作者表示感谢。问题:tarczfxx.tgz/xxx/xxx/A然后希望xx.tgz或xx.tar.gz里面就直接A这个目录不希望加前导xxx/xxx,我知道可以先cp这个目录到同一个目录再打包,不过想知道可以不可以不用另外cp到同一个目录 答案1:使用-C指定相对路径,如:tarczfx

    2022年5月6日
    77
  • 批处理简单教程

    批处理简单教程bat处理

    2022年8月22日
    9
  • WiFi模块 driver驱动框架(sdio接口、pcie接口)「建议收藏」

    WiFi模块 driver驱动框架(sdio接口、pcie接口)「建议收藏」1、WiFidriver驱动框架应用层BSDsocket层TCP/IP协议层IP层网络设备层MAC层(802.11)(包括扫描、认证、关联、省电状态)设备驱动层2、SDIO-Wifi模块1、SDIO-Wifi模块介绍SDIO-Wifi模块是基于SDIO接口的符合WiFi无线网络标准的嵌入式模块,内置无线网络协议IEEE802.11协议栈以及TCP/IP协议栈,能够实现用户主平台数据通过SDIO口到无线网络之间的转换。SDIO具有传输数据快,兼容SD、MMC接口等特点。对于SD

    2022年9月27日
    0
  • 3DCNN

    3DCNN学习论文Appearance-and-RelationNetworksforVideoClassification的时候看到了3DCNN,因为是第一次接触视频分类,因此,查询学习转自:https://blog.csdn.net/zouxy09/article/details/9002508最近看DeepLearning的论文,看到这篇论文:3DConvolutionalNeural…

    2022年6月11日
    45
  • 基于python的个人博客系统的设计开题报告_基于SSM的个人博客系统设计开题报告…「建议收藏」

    基于python的个人博客系统的设计开题报告_基于SSM的个人博客系统设计开题报告…「建议收藏」本科毕业设计(论文)开题报告题目:基于SSM的个人博客系统设计与实现专题题目(若无专题则不填):本课题来源及研究现状:关于博客的未来:在创办了博客中国(blogchina)、被誉为“博客教父”的方兴东接受了记者的专访。他认为,博客这一事物在中国的发展大致经过以下三个阶段:第一阶段是2002年至2003年,少数人写博;第二阶段是2003年至2005年,博客爱好者写博;第三阶段是2…

    2022年7月21日
    11

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号