[PY] 1966 : 프린터 큐

https://www.acmicpc.net/problem/1966

시간제한을 두고 풀었는데 지문 자체가 너무 이상해서 이해가 힘들었다.
내 탓을 해야겠다가도 종합적인걸 생각하면 마냥 내 잘못은 아니니까 괜찮아.

여기서 알려주는 것만 구현하면 된다. 다행히!

import sys
from collections import deque

testCaseCnt = int(sys.stdin.readline())


for i in range(testCaseCnt):
    docList = deque()
    docList.clear()

    docCnt, target = list(map(int, sys.stdin.readline().strip().split()))
    docListInput = list(map(int, sys.stdin.readline().strip().split()))[:docCnt]
    realTarget = [docListInput[target], target]
    for j in range(docCnt):
        docList.append([docListInput[j] , j])

    # 최대 힙에 모든 프린터 내용은 들어갔다. 그러면 이제 해야 할 일은?
    # realTarget이 나올 때 까지 heap에서 pop한다. 그리고 몇 번째의 몇을 처리하기 위해 +1을 먼저하고 Pop을 하기로 하자.

    mut = 0
    canContinue = True
    while canContinue:
        maxItem = max(docList)[0]
        item = docList.popleft()
        if(item[0] == maxItem):
            # 이 아이템이 내가 찾던 것 인지
            mut += 1
            if(item == realTarget):
                canContinue = False
                continue
        else:
            docList.append(item)
    
    print(f"{mut}")

'문제풀이' 카테고리의 다른 글

[PY]<!> 9935 : 문자열 폭발  (0) 2025.03.27
[PY] 10815 : 숫자카드  (0) 2025.03.27
[PY] 10830 : 행렬 제곱  (0) 2025.03.26
[PY] 6549 : 히스토그램에서 가장 큰 직사각형  (0) 2025.03.26
[PY] 2493 : 탑  (0) 2025.03.25