您的位置:首页 > 其它

Codeforces Round #321 (Div. 2)-A. Kefa and First Steps,暴力水过~~

2016-04-30 20:26 537 查看
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
,b
;
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: