BOJ - 1966 - 프린터 큐

Updated:

import sys

def solution():
    T = int(input())

    for _ in range(T):
        N, M = map(int, sys.stdin.readline().split(' '))
        printer = list(map(int, sys.stdin.readline().split(' ')))
        check = [False for _ in range(N)]
        check[M] = True
        count = 0

        while True:
            if printer[0] == max(printer):
                count += 1
                if check[0]:
                    print(count)
                    break
                else:
                    printer.pop(0)
                    check.pop(0)
            else:
                printer.append(printer.pop(0))
                check.append(check.pop(0))
solution()

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

Categories:

Updated:

Leave a comment