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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • MPEG-4、MPEG-4/AVC、H.264之间的联系与区别「建议收藏」

    MPEG-4、MPEG-4/AVC、H.264之间的联系与区别「建议收藏」当你在网上下载视频时,经常会看到MPEG-4、h.264等等词汇,它们之间有什么关系吗?  在视频编解码技术定义方面有两大标准机构。一个是国际电信联盟(ITU)致力于电信应用,已经开发了用于低比特率视频电话的H.26x标准,其中包括H.261、H.262、H.263与 H.264;另一个是国际标准化组织(ISO)主要针对消费类应用,已经针对运动图像压缩定义了MPEG

    2022年9月19日
    4
  • Android程序员的十大转型之路

    Android程序员的十大转型之路IT行业是一个瞬息万变的行业,程序员是一个不进则退的职业。我作为一个Android程序员,多年来一直保持随时可以转型其他技术领域的状态,保持对新技术敏感的嗅觉。

    2022年6月14日
    128
  • 未分配的磁盘怎么还原回去_硬盘突然未初始化

    未分配的磁盘怎么还原回去_硬盘突然未初始化大家是否遇到过此类问题,当将外部硬盘插入计算机并找到提示该驱动器已成功安装但没有出现在“此PC”上的通知?当进入Window的磁盘管理实用程序,发现磁盘是未知的,未初始化的,未分配的,那么如何修复未初始化的磁盘?还有丢失数据之后怎么找回?”第1部分:初始化磁盘意味着什么?初始化存储设备(非常类似于格式化过程)是一种擦除驱动器上的数据并允许其在以前不使用时可以再次使用的方法。要进行初始化,可以通过将…

    2022年9月2日
    4
  • docker下载安装教程_mac docker 性能

    docker下载安装教程_mac docker 性能前言Docker提供轻量的虚拟化,你能够从Docker获得一个额外抽象层,你能够在单台机器上运行多个Docker微容器,而每个微容器里都有一个微服务或独立应用,例如你可以将Tomcat运行在一个D

    2022年7月28日
    30
  • 激光雷达和超声波雷达区别_雷达是超声波还是电磁波

    激光雷达和超声波雷达区别_雷达是超声波还是电磁波转自:http://www.sohu.com/a/201826967_524185不知何时,自动驾驶技术从电影中跳出来,直接被拉到人们视野中。不过,去年特斯拉却因为几起自动驾驶事故,官网不得不把自动驾驶字眼改为辅助驾驶。本期《汽车总动员》讨论的不是自动驾驶,而是被称为自动驾驶汽车“眼睛”的雷达。目前主流的“眼睛”有四类——毫米波雷达、激光雷达、超声波雷达、摄像头。他们各自都有自己的特点,比如摄像头…

    2022年9月12日
    2
  • filter builder_苹果数据分析代码怎么看

    filter builder_苹果数据分析代码怎么看在FilterDispatcher中首先关注的方法是init()和doFilter(),两个有用的局部变量(或者状态)[code="java"]privateFilterConfigfilterConfig;protectedDispatcherdispatcher;[/code]filterConfig用来向filter传递信息,提供了四个方法:[code="java"]…

    2022年8月16日
    5

发表回复

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

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