Lower AtCoder - 4871

Lower

Problem Statement

There are N squares arranged in a row from left to right.

The height of the i-th square from the left is Hi.

You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square.

Find the maximum number of times you can move.

Constraints

  • All values in input are integers.
  • 1≤N≤105
  • 1≤Hi≤109

Input

Input is given from Standard Input in the following format:

N
H1 H2 … HN

Output

Print the maximum number of times you can move.

Sample Input 1

5
10 4 8 7 3

Sample Output 1

2

By landing on the third square from the left, you can move to the right twice.

Sample Input 2

7
4 4 5 6 6 5 5

Sample Output 2

3

By landing on the fourth square from the left, you can move to the right three times.

Sample Input 3

4
1 2 3 4

Sample Output 3

0

就是找最长的非减序列。。

#include<iostream>
#include<stack>
#include<algorithm>
using namespace std;
int n;
long long h[100010];
stack<long long> sa;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int sum=0;
	int maxx=0;
	for(int i=n-2;i>=0;i--){
		if(h[i]>=h[i+1]){
			sum++;
		}
		else{
			maxx=max(maxx,sum);
			sum=0;
		}
	}
	maxx=max(maxx,sum);
	cout<<maxx<<endl;
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值