백준 - 1966

Giho Kim·2023년 9월 17일

코테 연습

목록 보기
7/26

문제

  1. 일단 for i in range(N)으로 문서를 만든다.
  2. 중요도에서 max를 찾는다
  3. while importance: 일때 popleft()가 max가 아니라면 다시 append해준다. 문서도 같이
  4. max라면 빼준뒤 cnt += 1 또한 문서도 빼준다
  5. 만약 문서의 popleft()가 M과 같고 max라면 cnt += 1 후 break
import sys
from collections import deque
T = int(input())

for i in range(T):
  N, M = list(map(int,sys.stdin.readline().split()))
  importances = deque(list(map(int, sys.stdin.readline().split())))
  max_import = max(importances)
  cnt = 0
  order_lst = deque([i for i in range(N)])

  while order_lst:
    pop_order = order_lst.popleft()
    pop_import = importances.popleft()

    if pop_import == max_import:
      cnt += 1
      if pop_order == M:
        print(cnt)
        break
      else:
        max_import = max(importances)

    
    else:
      order_lst.append(pop_order)
      importances.append(pop_import)
profile
취준돌이 개발자 김기호

0개의 댓글