This article is an extra article of Competitive Programming is What.
If you implement it, it will be an article with the source code of.
To make it easier for people who are not doing python, There are some parts that are redundant code (for competition pros), but please forgive me.
# coding: utf-8
#Magic for python that speeds up standard input acquisition
import sys
input = sys.stdin.readline
#Get while converting standard input numerically
N = int(input())
#Get standard input while converting array & number
H = [int(x) for x in input().split()]
#Calculate the maximum distance that can be moved when landing on each square
#Definition of variables for storing the travelable distance
ans = []
#Shift the start position from the beginning
for i in range(N):
count = 0
#Check how much you can move from the start position
for j in range(i,N-1):
if H[j] >= H[j+1]:
#If you can move, increase the distance you can move
count += 1
else:
#End if not moveable
break
#Add to the list of travelable distances
ans.append(count)
#Displaying answers
print(max(ans))
# coding: utf-8
#Magic for python that speeds up standard input acquisition
import sys
input = sys.stdin.readline
#Get while converting standard input numerically
N = int(input())
#Get standard input while converting array & number
H = [int(x) for x in input().split()]
#So far together
#Processing-like variable definition
max_count = 0
tmp_count = 0
#Start from the beginning
for i in range(N-1):
if H[i] >= H[i+1]:
#Increase the distance count if you can move
tmp_count += 1
else:
#When it is not possible to move, the distance that can be moved up to that point
#Compare current maximum travel distance
if tmp_count > max_count:
#Since the movable distance this time is larger, I will update it
max_count = tmp_count
#Reset the current travel distance
tmp_count = 0
#The loop end is N-Since it is 1, if you can move from a certain point to the right end,
#Since the distance traveled has not been compared to the maximum distance traveled,
#Use max and use the larger value as the answer
print(max(max_count,tmp_count))
Recommended Posts