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

原题: http://codeforces.com/contest/580/problem/A


题目大意: 给一个数组, 找最大的连续非递减子数组.


分析: 这个…就扫一下, count一下每次有多少个连续的数是非递减的, 注意的是counter要从1开始. 因为如果一个数, 自己就是非递减的.

public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.readInt();
        int max = 1;
        int cur = 1;
        int[] ary = IOUtils.readIntArray(in,n);
        for (int i = 1; i < ary.length; i++) {
            if (ary[i] >= ary[i-1])
                cur++;
            else
                cur = 1;
            max = Math.max(max, cur);
        }
        out.print(max);
    }