链接:

https://codeforces.com/contest/1272/problem/D

题意:

You are given an array a consisting of n integers.

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

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

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

思路:

正着反着算一边,能往两边延长的最大长度,对每个点特判。

代码:

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+10; int Dp[MAXN], a[MAXN], Dpr[MAXN];
int n; int main()
{
cin >> n;
for (int i = 1;i <= n;++i)
cin >> a[i];
int ans = 1;
Dp[0] = Dpr[n+1] = 0;
Dp[1] = Dpr[n] = 1;
for (int i = 2;i <= n;++i)
{
if (a[i] > a[i-1])
Dp[i] = Dp[i-1]+1;
else
Dp[i] = 1;
}
for (int i = n-1;i >= 1;--i)
{
if (a[i] < a[i+1])
Dpr[i] = Dpr[i+1]+1;
else
Dpr[i] = 1;
}
for (int i = 2;i <= n;++i)
{
ans = max(ans, Dp[i]);
if (a[i] > a[i-2])
ans = max(ans, Dp[i-2]+Dpr[i]);
}
cout << ans << endl; return 0;
}

最新文章

  1. SpringMVC初始化参数绑定--日期格式
  2. codefordream 关于js初级训练
  3. 设置 Unix,Linux环境下的NLS_LANG
  4. Jquery开灯关灯效果
  5. 配置Chrome Driver
  6. 为什么需要Bundler
  7. 从逆向的角度去理解C++虚函数表
  8. Swift中的数组
  9. mysql的小知识点(关于数据库的导入导出 对于windows)
  10. org.pentaho.di.ui.core.widget.PasswordTextVar
  11. C# 中的sealed修饰符学习
  12. TabHost理解与使用
  13. css属性之vertical-align详解
  14. 1、发布C++实现的TCP网络框架Khala
  15. UIStepper UISlider UISwitch UITextField 基本控件
  16. 洛谷-哥德巴赫猜想(升级版)-BOSS战-入门综合练习1
  17. C++基础知识1
  18. css学习の第三弹—盒模型的创建和使用
  19. mac下利用Breakpad的dump文件进行调试
  20. [bzoj1063][Noi2008]道路设计

热门文章

  1. SGU 128. Snake --- 暴力枚举+并查集+贪心+计算几何
  2. 【题解】Luogu P5400 [CTS2019]随机立方体
  3. python程序打包exe文件
  4. 2019 拼多多java面试笔试题 (含面试题解析)
  5. jQuery-使页面回到顶部
  6. 供应链管理如何提高效率?APS系统成优化引擎
  7. java Document生成和解析xml
  8. python基础-函数递归
  9. jemter csv参数化时注意问题
  10. iframe页面script交互