728x90
반응형
숫자들이 담긴 큐와, 인덱스들이 담긴 리스트를 같이 사용해서 풀어야 하는 문제이다.
from collections import deque
for _ in range(int(input())):
N, M = map(int, input().split())
queue = deque(map(int, input().split()))
index = [0 for _ in range(N)]
index[M] = 1
cnt = 0
while 1:
if queue[0] == max(queue):
if index[0] == 1:
break
else:
queue.popleft()
index.pop(0)
cnt += 1
else:
queue.append(queue.popleft())
index.append(index.pop(0))
print(cnt+1)
728x90
반응형
'Agorithm > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 18111번 마인크래프트 (python) (0) | 2021.03.06 |
---|---|
백준 알고리즘 2504번 괄호의 값(python) (0) | 2021.03.06 |
백준 알고리즘 2164번 카드2(python) (0) | 2021.03.05 |
백준 알고리즘 11866번 요세푸스 문제 0(python) (0) | 2021.03.05 |
백준 알고리즘 6198번 옥상 정원 꾸미기(python) (0) | 2021.03.05 |