Codeforces 580A

来源:互联网 发布:全国各地一手车主数据 编辑:程序博客网 时间:2024/06/06 04:27

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 makesai 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
62 2 1 3 4 1
output
3
input
32 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 <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>
using namespace std;
int a[100010];
int b[10001];
int main()
{
    int n;
    while(cin>>n){
        int t=1,l=1;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=1;i<n;i++){
            if(a[i]>=a[i-1]){
                l++;
            }
            else l=1;
            if(l>t) t=l;
        }
        cout<<t<<endl;
    }
    return 0;
}