백준 1966 - 프린터 큐 (파이썬)
Updated:
Answer
from collections import deque
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, m = map(int, input().split())
q = deque(list(map(int, input().split())))
a = deque([0] * n)
a[m] = 1
cnt = 0
while True:
if q[0] == max(q):
cnt += 1
if a[0] == 1:
print(cnt)
break
else:
q.popleft()
a.popleft()
else:
q.append(q.popleft())
a.append(a.popleft())