ORIGIN

AtCoder-4871 Lower

ACM 1 mins301 words

See the original article https://dyingdown.github.io/2019/11/17/AtCoder-4871-Lower/

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 $H_i$.

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.

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

Input

Input is given from Standard Input in the following format:

1
2
N
H1 H2 … HN

Output

Print the maximum number of times you can move.

Sample Input 1

1
2
5
10 4 8 7 3

Sample Output 1

1
2

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

Sample Input 2

1
2
7
4 4 5 6 6 5 5

Sample Output 2

1
3

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

Sample Input 3

1
2
4
1 2 3 4

Sample Output 3

1
0

Analysis

Since the data is small and the time is long, you can use violent methods.

If the this number is no smaller than the previous number, answer = answer + 1;

Else answer = 0

The max number = max(max number, answer).

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<bits/stdc++.h>

using namespace std;

int main(){
int n;
cin >> n;
int pre = 0, now = 0, count = 0, maxn = 0;
cin >> pre;
for(int i = 1; i < n; i ++) {
cin >> now;
if(now <= pre) {
count ++;
} else {
maxn = max(maxn, count);
count = 0;
}
pre = now;
}
maxn = max(maxn, count);
cout << maxn << endl;
}
TOP
COMMENT
  • ABOUT
  • |
o_oyao
  The Jigsaw puzzle is incomplete with even one missing piece. And I want to be the last piece to make the puzzle complete.
Like my post?
Default QR Code
made with ❤️ by o_oyao
©o_oyao 2019-2024

|