Algorithm/Implementaion

[백준] 1966번 프린터 큐

등촌동 꼬북이 2020. 11. 25. 17:44

쉬운 문제..

 

import sys
T = int(sys.stdin.readline())

for i in range(T):
    ans = 0
    N, M = map(int, sys.stdin.readline().split())
    tc = list(map(int, sys.stdin.readline().split()))
    tm = [0] * N
    tm[M] = 1
    popData = max(tc)
    while True:
        tempM = tm.pop(0)
        tempC = tc.pop(0)
        if tempC == popData:
            ans += 1
            if tempM == 1:
                break
            popData = max(tc)
        else:
            tc.append(tempC)
            tm.append(tempM)
    print(ans)