백준 1966번: 프린터 큐

Couch Potato·2020년 9월 23일
0

algorithm

목록 보기
6/15

프린터 큐

 def solution(N,M,importance):
    cnt = 0
    idx_list = [i for i in range(N)]
    #
    # # 먼저 cnt + 1 하여 출력 순서 (X)
    # # case 1. 제일 우선순위가 index M과 같을 경우, 출력 cnt + 1 하고서 BREAK
    # # case 2. 제일 우선순위는 지우고 출력 cnt + 1 하고서 CONTINUE
    # # case 3. 아무것도 아닐 경우, POP시키고 다시 WHILE문
    while(1):
        # 1.
        if importance[0] == max(importance) and idx_list[0] == M:
             cnt += 1
             break
        # 2.
        elif importance[0] == max(importance): #
            cnt += 1
            idx_list.pop(0)
            importance.pop(0)
        # 3.
        else:
            idx_list.append(idx_list.pop(0))
            importance.append(importance.pop(0))
    return cnt

test_case = int(input())
answer = []
for i in range(test_case):
    N, M = map(int, input().split())
    importance = list(map(int, input().split()))
    answer.append(solution(N,M,importance))

for i in answer:
    print(i)

0개의 댓글