且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

580A. Kefa and First Steps (Codeforces Round #321 (Div. 2))

更新时间:2021-10-22 00:13:48

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 sequenceai. 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.

Sample test(s)
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.

题目大意:

寻找最长的非递减数列(也可以说是递增的最长数列,但是可以有相等的情况),输出长度

解题思路:

先将每一个非递减数列的长度存入一个sum数组里,然后再从大到小排一下序就ok了,

输出sum[0];

上代码:

/**
2015 - 09 - 24 晚上

Author: ITAK

Motto:

今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标,不断地超越自己。
**/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 1e5+5;
const int mod = 1e9+7;
const double eps = 1e-7;

int cmp(int a, int b)
{
    return a > b;
}
int arr[maxn], sum[maxn];
int main()
{
    int n, k=0;
    cin>>n;
    memset(sum, 0, sizeof(sum));
    for(int i=0; i<n; i++)
        cin>>arr[i];
    for(int i=1; i<n; i++)
    {
        if(arr[i] >= arr[i-1])
            sum[k]++;
        else
            k++;
    }
    ///cout<<"k == "<<k<<endl;
    sort(sum, sum+k+1, cmp);

    cout<<sum[0]+1<<endl;
    return 0;
}