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.

思路;这个题当时过的比较顺利,再做一下,竟然发现忽略了一处,还是弱。
希望以后AC不靠侥幸。
这是一开始做的,想法比较复杂,但很缜密,考虑的情况也多。

#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
long long a[100100];
int main()
{
int i;
int n;
while(~scanf("%d",&n))
{
int cnt=1;
int maxn=1;
for(i=0;i<n;i++)
scanf("%lld",&a[i]);
int flag=0;
int j=0;
while(j!=n-1)/
{
for(j=flag;j<n-1;j++)
{
if(a[j]<=a[j+1])
cnt++;
else{
flag=j+1;
break;
}
}
maxn=max(maxn,cnt);
cnt=1;
}
printf("%d\n",maxn);
}
return 0;
}

后来补做的。
这样更容易理解一些。
如果说acm 教会了我什么,那就是在任何时候都要冷静分析。

#include<stdio.h>
long long a[100010];
int main()
{
int n;
long long maxn=-1;
while(~scanf("%d",&n))
{
maxn=-1;
int i,flag=0;
long long cnt=1;
for(i=0; i<n; i++)
scanf("%lld",&a[i]);
for(i=0; i<n-1; i++)
{
if(a[i]<=a[i+1])
cnt++;
else
cnt=1;
if(cnt>maxn)
{
maxn=cnt;//随时更新maxn的值。
}
}
printf("%lld\n",maxn);
}
return 0;
}