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

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • ubuntu 卸载软件命令_linux卸载软件包命令

    ubuntu 卸载软件命令_linux卸载软件包命令彻底删除软件sudoapt-getpurgeXXX 清楚残留sudoapt-getautoremove        sudoapt-getclean

  • [奶奶看了都会]京东自动签到薅羊毛-完整教程

    [奶奶看了都会]京东自动签到薅羊毛-完整教程又到了节假日的时间了,每逢节假日必须得搞事情。最近北京疫情管的比较严,楼主去小区旁边的小公园散步,都要出示核酸证明了。。。上一次说到用脚本完成京东自动签到领京豆:[奶奶看了都会]教你用脚本薅京东签到羊毛这个只能领到自动签到任务的豆子而已,还有好多京豆任务都没做了,导致咱白白损失了一波豆豆?所以今天嘛,我们就把京豆的任务都做一遍,把京豆全给领了?手机抓包为了获取到京豆签到的接口,需要在手机京东APP上抓包,这就需要用到手机抓包的技术了楼主对着网上的教程实践了一波,搞了一整天之后,得到的结论是An

  • 十二个开源UML工具

    十二个开源UML工具本文将为您介绍12个优秀的UML工具:1.StarUMLStarUML(简称SU),是一种创建UML类图,是一种生成类图和其他类型的统一建模语言(UML)图表的工具。StarUML是一个开源项目之一发展快、灵活、可扩展性强(zj)。2.NetbeansUMLPlugin目前支持:Activity图,Class图,Sequence图,State图以及Use…

  • 无法配置成功idea里的tomcat_idea配置没有配置tomcat这个选项

    无法配置成功idea里的tomcat_idea配置没有配置tomcat这个选项IntelliJ使用##使用IntelliJIDEA配置web项目时,选择EditConfigration部署Tomcat的Deployment可能会出现以下情况:导致新手部署过程中摸不着头脑。 解决办法: 1、打开ProjectStructure; 2、选择Aritfacts选项: 3、点击+号,选择WebApplication:Exploded-&gt;FromMod…

    2022年10月17日
  • Jmeter下载安装配置—测试小白

    Jmeter下载安装配置—测试小白一,进入官网:http://jmeter.apache.org/1.第一步进入官网如下图2.选择进行下载,下载下来为一个压缩包,解压即可。3.我下载的是jmeter4.0版本,对应jdk1.8。然后就进行解压。个人认为要注意3点:1.解压之后压缩包叫apache-jmeter-4.0.zip,如是src.zip后缀的都不对,打开之后会报错不可用,因为里面缺少我们下一步将要配置的环境变量.jar文件…

  • Java 发送邮件的几种方式[通俗易懂]

    Java 发送邮件的几种方式[通俗易懂]发送文件的项目地址(free):https://download.csdn.net/download/qq_36474549/10741073导入jar包:activation-1.1.jar  javax.mail-1.6.2.jar内容:1.发送一封只包含文本的简单邮件   SendEmail_text.java      2.发送包含内嵌图片的邮件   Send…

发表回复

您的电子邮箱地址不会被公开。

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