247일차 - BOJ no.1966

Dzeko·2022년 3월 26일
0

Daily Algorithm

목록 보기
244/396
post-thumbnail

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

My Solution

import sys
from collections import deque

T = int(sys.stdin.readline().rstrip())
for _ in range(T):
    n, m = map(int, sys.stdin.readline().rstrip().split())
    arr = deque(list(map(int, sys.stdin.readline().rstrip().split())))

    target_arr = deque([0 for _ in range(n)])
    target_arr[m] = 1

    cnt = 0
    while arr:
        if arr[0] == max(arr):
            x = arr.popleft()
            y = target_arr.popleft()
            cnt += 1
            if y == 1:
                break
        else:
            x = arr.popleft()
            y = target_arr.popleft()
            arr.append(x)
            target_arr.append(y)
    print(cnt)
m번째 있는 수를 몇번 째에 뽑아내는 지를 이해하는데 오래걸렸다 푸는 데에는 오래 걸리지 않았다.

#큐

profile
Hound on the Code

0개의 댓글