我是靠谱客的博主 风趣老鼠,这篇文章主要介绍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.


就是把两段连上就行了
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
    int n;
    int f1[111111],f2[111111],a[111111];
    cin>>n;
    cin>>a[0];
    f1[0]=1;
    for(int i=1; i<n; i++)
    {
        cin>>a[i];
        f1[i]=1;
        if(a[i]>a[i-1])
            f1[i]+=f1[i-1];
    }
    f2[n-1]=1;
    for(int i=n-2; i>=0; i--)
    {
        f2[i]=1;
        if(a[i]<a[i+1])
            f2[i]+=f2[i+1];
    }
    int maxx=1;
    for(int i=1; i<n; i++)
    {
        maxx=max(maxx, f1[i-1]+1);
        maxx=max(maxx, f2[i]+1);
        if(i<n-1 && a[i-1]<a[i+1]-1)
            maxx=max(maxx, f1[i-1]+1+f2[i+1]);
    }
    cout<<maxx<<endl;
    return 0;
}




最后

以上就是风趣老鼠最近收集整理的关于Codeforces Round #FF (Div. 2)C. DZY Loves Sequences的全部内容,更多相关Codeforces内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(138)

评论列表共有 0 条评论

立即
投稿
返回
顶部