[백준] 프린터 큐
자료구조 큐 활용
파이썬
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
for i in range(n):
cnt=0
a,b = map(int,input().split())
q = deque(list(map(int,input().split())))
while len(q) > 0:
m = max(q)
if q[0] == m:
q.popleft()
if b == 0:
cnt += 1
break
else:
cnt += 1
b -= 1
else:
i = q.popleft()
q.append(i)
if b == 0:
b += len(q) - 1
else:
b -= 1
print(cnt)
댓글남기기