-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yjhss
committed
Apr 26, 2023
1 parent
f9570f2
commit a1e7e02
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import sys | ||
|
||
t = int(sys.stdin.readline()) # 테스트 케이스 개수 t | ||
|
||
for i in range (t): | ||
n, m = map(int, input().split()) | ||
queue = list(map(int, input().split())) # 리스트 queue | ||
cnt = 0 # 문서의 출력 순서를 세기 위한 변수 cnt | ||
|
||
while queue: | ||
if queue[0] == max(queue): # 맨 앞 문서의 중요도가 가장 클 때 | ||
del queue[0] # 맨 앞 문서 삭제 | ||
m -= 1 # 문서 위치 왼쪽으로 한 번 이동하므로 m 값 1 감소 | ||
cnt +=1 # 문서 하나 출력 되었으므로 cnt 값 1 증가 | ||
else: # 맨 앞 문서의 중요도가 가장 크지 않을 때 | ||
queue.append(queue[0]) # 이 문서를 맨 뒤에 추가 | ||
del queue[0] # 맨 앞에서 삭제 | ||
|
||
if m == 0: # m이 0일 경우 | ||
m = len(queue)-1 # m 맨 뒤 가리킴 | ||
else: # m이 0이 아닐 경우 | ||
m -= 1 # m 값 1 감소 | ||
|
||
print(cnt) # cnt 값 출력 |