A. Kefa and First Steps
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th
day (1 ≤ i ≤ n) he makes ai money.
Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai.
Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.

Help Kefa cope with this task!

Input

The first line contains integer n (1 ≤ n ≤ 105).

The second line contains n integers a1,  a2,  ...,  an (1 ≤ ai ≤ 109).

Output

Print a single integer — the length of the maximum non-decreasing subsegment of sequence a.

Examples
input
6
2 2 1 3 4 1
output
3
input
3
2 2 9
output
3
Note

In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.

In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.

这个题有点像求非单调递减子序列的长度,但仔细看看题发现是求连续一段非单减子数组的长度,这样和求单调递增子序列的方法很像,但看到数据范围两层循环遍历肯定会超时,题目要求的是子区间非单减的长度,为何要遍历呢?只需判断当前输入的值是否大于等于前一个的值,如果是,则此时的长度就等于前一个长度加一,反之,则此时长度为一,然后继续。看代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=100000+10;
int a[N],b[N];
int main()
{
int n,i,j;
while(~scanf("%d",&n))
{
memset(b,0,sizeof(a));
int maxx=0;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
b[i]=1;
for(j=i;j>=1;j--)
{
if(a[j]>=a[j-1]&&j!=1)
b[i]=b[j-1]+1;//用到了点动归思想;
break;//这样就不会超时了,甚至可以简化之;
}
maxx=max(maxx,b[i]);
}
printf("%d\n",maxx);
}
return 0;
}

最新文章

  1. TCP流量控制与拥塞控制
  2. iOS中的__typeof与typeof
  3. POJ3635 Full Tank?(DP + Dijkstra)
  4. 设置h5页面不可复制文字
  5. SQL Server Schema
  6. GitHub详解(转)
  7. PHP微信支付开发之扫描支付(模式二)后如何回调
  8. Oracle的正则函数之regexp_like
  9. Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.commons.EmptyVisitor
  10. 用js来实现那些数据结构14(树02-AVL树)
  11. jQueryUI中Datepicker(日历)插件使用
  12. OpenStack 部署步骤详解(mitaka/ocata/一键部署)
  13. git push 每次都要输入用户名密码
  14. Flutter - Error: &#39;xxx&#39; is imported from both package...
  15. HDU2883_kebab
  16. hdoj1879 继续畅通工程(Prime || Kruskal)
  17. JQuery包装集size,length,index,slice,find,filter,is,children,next,nextAll,parent,parents,closest,siblings,add,end,andSelf的用法
  18. PHP中类型约束
  19. 2015 DevOps状态调查报告
  20. 题解【luoguP3644 [APIO2015]八邻旁之桥】

热门文章

  1. 分区表,磁盘概念和parted的使用
  2. Mysql选择合适的存储引擎
  3. shell随机数生成
  4. R 关于全局变量
  5. [转]MVC 检测用户是否已经登录
  6. jQuery在$(function(){})中調用函數
  7. elasticsearch-sql安装
  8. css3 blur模糊解决ie6-ie9兼容
  9. 什么是Entitlement
  10. pagehelper 分页