You are given an array aa consisting of nn integers.

You can remove at most one element from this array. Thus, the final length of the array is n−1n−1 or nn.

Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array.

Recall that the contiguous subarray aa with indices from ll to rr is a[l…r]=al,al+1,…,ara[l…r]=al,al+1,…,ar. The subarray a[l…r]a[l…r] is called strictly increasing if al<al+1<⋯<aral<al+1<⋯<ar.

Input
The first line of the input contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the number of elements in aa.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109), where aiai is the ii-th element of aa.

Output
Print one integer — the maximum possible length of the strictly increasing contiguous subarray of the array aa after removing at most one element.

Examples
Input
5
1 2 5 3 4
Output
4
Input
2
1 2
Output
2
Input
7
6 5 4 3 2 4 3
Output
2
Note
In the first example, you can delete a3=5a3=5. Then the resulting array will be equal to [1,2,3,4][1,2,3,4] and the length of its largest increasing subarray will be equal to 44.
思路:最多删除一个,那么我们就记录这一个数字前一个数字和后一个数字的最长连续序列。然后贪心的取最大值。事先用dfs预处理好每一个数字最远可以到达哪里。具体看代码。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;const int maxx=2e5+100;
int a[maxx];
int dp[maxx];
int np[maxx];
int n;inline void dfs(int &i,int &cnt)
{if(i==n) {dp[n]=1;i+=1;return ;}int ant=cnt,j=i;if(a[i+1]>a[i]) dfs(i+=1,cnt+=1);else i+=1;dp[j]=cnt-ant+1;
}
inline void dfs1(int &i,int &cnt)
{if(i==1){np[i]=1;i-=1;return ;}int ant=cnt,j=i;if(a[i-1]<a[i]) dfs1(i-=1,cnt+=1);else i-=1;np[j]=cnt-ant+1;
}
int main()
{scanf("%d",&n);int _max=0;a[n+1]=a[0]=0;for(int i=1;i<=n;i++) {scanf("%d",&a[i]);}int cnt;for(int i=1;i<=n;) dfs(i,cnt=0);//dp[i]代表的是第i位开始,最长的上升序列,i++for(int i=n;i>=1;) dfs1(i,cnt=0);//np[i]代表的是第i位开始,最长的下降序列,i--for(int i=1;i<=n;i++) _max=max(_max,dp[i]);for(int i=2;i<n;i++) if(a[i-1]<a[i+1]) _max=max(_max,np[i-1]+dp[i+1]);//贪心的取最大值cout<<_max<<endl;return 0;
}//1 2 3 4 5 6

努力加油a啊,(o)/~

Remove One Element(贪心)相关推荐

  1. queue方法中add,offer,remove,poll,element,peek的用法和区别

    queue方法中add,offer,remove,poll,element,peek的用法和区别 1.add()和offer()两者都是往队列尾部插入元素. 不同是,当超出队列界限(容量)的时候,ad ...

  2. Remove specific element by editing the array

    function removeWithoutCopy(arr, item) {for(var i=0;i<arr.length;i++){if(arr[i]===item){arr.splice ...

  3. 【CodeForces - 1038C】Gambling (博弈问题,优先队列模拟,贪心)

    题干: Two players A and B have a list of nn integers each. They both want to maximize the subtraction ...

  4. Jquery empty() remove() detach() 方法的区别

    方法简介: empty() This method removes not only child (and other descendant) elements, but also any text ...

  5. java removeto_java.util.LinkedList.remove(int index)方法实例

    全屏 java.util.LinkedList.remove(int index)方法删除在此列表中的指定位置的元素. 声明 以下是java.util.LinkedList.remove()方法的声明 ...

  6. cypress 的错误消息 - the element has become detached or removed from the dom

    这个错误消息的分析和解决方案,可以参考 Cypress 的官方文档. 这个错误消息提示我们,我们编写的 Cypress 代码正在同一个"死去"的 DOM 元素交互. 显然,在真实的 ...

  7. Remove Extra One(思维)

    You are given a permutation p of length n. Remove one element from permutation to make the number of ...

  8. array remove java_how to remove array from another array in javascript

    可以将文章内容翻译成中文,广告屏蔽插件会导致该功能失效: 问题: 0: {id: 1553825061863, name: "Thai Milk Tea", qty: " ...

  9. 【Codeforces - 900C】Remove Extra One(思维,STLset,tricks)

    题干: You are given a permutation p of length n. Remove one element from permutation to make the numbe ...

最新文章

  1. 通过代码自定义cell(cell的高度不一致)
  2. python模拟通讯录的删除功能_python+uiautomator2 实现需求:从通讯录添加手机号码,若存在旧的 SOS号码,先删除再添加,若通讯录中没有号码,需先新建。...
  3. iptables下开放ftp连接端口
  4. 汉克尔变换matlab,HankelTransform
  5. jquery 获取系统默认年份_你没有看错,爬网页数据,C# 也可以像 Jquery 那样
  6. android aptx固件,新增aptX蓝牙发射协议,M5固件首次升级!
  7. css编写规则BEM
  8. axi dma 寄存器配置_STM32 ADC多通道转换的DMA传输示例
  9. USB 3.1 与 Type-C 接口有什么关系呢
  10. html字母间距属性,html – 是否可以相对于font-size具有字母间距并正确继承?
  11. 接口和一些抽象类的区别
  12. P2962 [USACO09NOV]灯Lights 对抗搜索
  13. Kodak Preps 8 for Mac(专业拼版软件)
  14. 深入理解JVM - 系统性能优化
  15. python识别颜色验证码_用Python识别验证码
  16. 腾讯/京东/网易校招笔试刷人超70%,这份笔试自救指南请收好
  17. navicat 使用ssh连接腾讯云主机mysql数据库(保姆级教程)
  18. Youtube 视频下载
  19. HBase 事务性 (Transaction)
  20. 每日刷题记录 (八)

热门文章

  1. 使用XmlTextWriter生成XML文件的方法
  2. IOS的Alamofire5.4高版本上传图片
  3. IOS OC项目的单例模式
  4. IOS之Swift的CoreData入门使用案例
  5. 从服务器检索时出错dfdferh01_大数据实战项目之海量人脸特征检索解决方案演进...
  6. 文件包含——php伪协议(五)
  7. python sendto函数返回值_有返回值的函数amp;闭包(python)
  8. 蓝牙配对码配置错误_安卓系统蓝牙配对流程分析
  9. c语言 集中上机题目,C语言集中上机题目.doc
  10. linux睿频是自动的吗,Linux限制cpu睿频限制频率