- 문제 해석
- 가로 N, 세로 100 크기의 공간에 수직으로 상자가 쌓여있다. 공간을 오른쪽으로 회전해 중력으로 상자들이 낙하할 때, 가장 큰 낙차 구하기
- 입력
- 공간 가로 크기 N
- 쌓여있는 상자 높이 리스트 Arr
- 출력
- 아이디어
- 기준의 맨 위쪽상자 기준 오른쪽에 높이가 같거나 높은 상자가 있다면, 낙차는 N - 자기자신의 위치인덱스 - 같거나 더 높게 쌓인 상자 개수 or N - 자기자신1 - 같거나 더 높게 쌓인 상자 개수
- 회전하기 전 가장 왼쪽의 맨 위쪽에 있는 상자가 낙차가 클 가능성이 가장 높다.
- 전체 상자에 대해서 enumerate으로 for문을 돌아야 하나? 아니면 포인터로 낙차 더해가면서 while문? 아니면 맨 왼쪽만 탐색해도 될까? ⇒ 일단 while문으로 가자!
- 필요변수
- 임의의 최대낙차값 dropMax
- 낙차 drop
- 코드(while문)
for tc in range(1, int(input()) + 1):
N = int(input())
Arr = list(map(int, input().split()))
dropMax = 0
s, e = 0, 0
e += 1
drop = 0
while e < N:
if Arr[s] > Arr[e]:
drop += 1
e += 1
if drop > dropMax:
dropMax = drop
if s==N-2:
break
if e == 9:
s += 1
e = s + 1
drop = 0
print(f'#{tc} {dropMax}')
for tc in range(1, int(input()) + 1):
N = int(input())
Arr = list(map(int, input().split()))
cnt = 0
for i in range(1, N):
if Arr[0] <= Arr[i]:
cnt += 1
drop = N - 1 - cnt
print(f'#{tc} {drop}')
for tc in range(1, int(input()) + 1):
N = int(input())
Arr = list(map(int, input().split()))
dropMax = 0
for i, e in enumerate(Arr):
cnt = 0
for j in range(i, N):
if e <= Arr[j]:
cnt += 1
drop = N - i - cnt
if dropMax < drop:
dropMax = drop
print(f'#{tc} {dropMax}')