Petya and Countryside(子序列问题)

Petya and Countryside
Time Limit:2000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

Description

Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle1 × n in size, when viewed from above. This rectangle is divided inton equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.

Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a1 × 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:

As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.

Input

The first line contains a positive integer n (1 ≤ n ≤ 1000). The second line containsn positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.

Output

Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.

Sample Input

Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
题意分析:
输入一串整数,求它的连续子序列(此序列中存在最打大值,然后两边依次减小)的最大长度
如例二
最长子序列为1  2 1长度为3
例三
1 1 1 3 3 4 长度为6;
解题思路:
从头开始,逐步列举:
代码:
#include<stdio.h>
int main()
{
	int a[1000],m,n,l;
while(~scanf("%d",&n))
{l=0;
int i,j,k;
for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
	for( i=0;i<n;i++)
	{
		for( j=i;j<n-1;j++)
		{
			if(a[j]>a[j+1])
			break;
		}
		for(k=j;k<n-1;k++)
		{
			if(a[k]<a[k+1])
			break;
		}
		if(k-i+1>l)
		l=k-i+1;
	}
	printf("%d\n",l);
}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值