문제
https://www.acmicpc.net/problem/1966
import sys
def solution(a,b,l):
temp=b
answer=0
while l: #큐에 문서가 있는 동안
m=max(l) #우선 순위가 높은 문서 저장
# 큐의 첫번째 문서가 우선순위가 가장 높지 않은 경우
if l[0]!=m:
l.append(l.pop(0)) #첫번째 문서를 뽑아서 큐의 마지막에
if temp==0:
temp=len(l)-1
else:
temp-=1
#큐의 첫번째 문서가 우선 순위가 높지만 지정된 문서는 아닌 경우
elif l[0]==m and temp!=0:
l.pop(0)
temp-=1
answer+=1
#큐의 첫번째 문서가 우선 순위가 높고 지정된 문서인 경우
elif l[0]==m and temp==0:
answer+=1
print(answer)
break
n=int(sys.stdin.readline().rstrip())
for _ in range(n):
a,b=map(int,sys.stdin.readline().split())
l=list(map(int,sys.stdin.readline().split()))
solution(a,b,l)