- 정말 쉬운 문제처럼 보여서 괜찮았는데 4트만에 정상적으로 출력되었다.
- 질문게시판에 있는 반례 내용에서 깨달음을 얻어 코드를 거듭 수정하면서 작성했다.
입력
5
1 1 1 1 1
출력
5
📌 테스트케이스의 결과를 확인해보자. 증가하는 수열의 길이는 5가 나오고 감소하는 수열의 길이 역시 5가 나오므로 답은 5가 나온다.
입력
5
3 1 1 1 1
출력
5
📌 테스트케이스의 결과를 확인해보자. 증가하는 수열의 길이는 4가 나오고 감소하는 수열의 길이는 5가 나오므로 답은 5가 나온다.
N = int(input())
N_lst = list(map(int, input().split()))
increase_max = 1
increase_length = 1
for i in range(len(N_lst)-1):
if N_lst[i] <= N_lst[i+1]:
increase_length += 1
else:
if increase_length > increase_max:
increase_max = increase_length
increase_length = 1
else:
increase_length = 1
if increase_length > increase_max:
increase_max = increase_length
decrease_max = 1
decrease_length = 1
for i in range(len(N_lst)-1, 0, -1):
if N_lst[i-1] >= N_lst[i]:
decrease_length += 1
else:
if decrease_length > decrease_max:
decrease_max = decrease_length
decrease_length = 1
else:
decrease_length = 1
if decrease_length > decrease_max:
decrease_max = decrease_length
print(max(increase_max, decrease_max))