Codeforces #61 (div2) B "Petya and Countryside"

問題:http://codeforces.com/contest/66/problem/B

高さの違う長方形の数とそれぞれの長方形の高さが与えられる.長方形のいずれかの上で雨が降ったとき,その水が流れる長方形の範囲を求める.

段々になってるかを調べる.

コード

import java.util.*;

public class B_PetyaAndCountryside {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = s.nextInt();
		}
		int r = 0;
		for (int i = 0; i < n; ++i) {
			int c = 1;
			for (int j = i - 1; j >= 0 && a[j + 1] >= a[j]; --j) {
				++c;
			}
			for (int j = i + 1; j < n && a[j - 1] >= a[j]; ++j) {
				++c;
			}
			r = Math.max(r, c);
		}
		System.out.println(r);
	}
}