728x90

< 해결 방법 > 

안풀리다가 갑자기 새로운 리스트 하나를 더 만들면 풀릴 것 같다는 생각이 들어 찾으려는 index에 'find' 를 넣은 리스트 하나를 더 만들어 주었고, 생각보다 쉽게 풀렸다.

 

import sys
from collections import deque
 
time = int(input())
 
def check(k,find):
    answer = 0
 
    while True:
        if k[0]==max(k):
            if find[0]=="find":
                return answer+1
            else:
                del k[0]
                del find[0]
                answer+=1
        else:
            k.append(k[0])
            find.append(find[0])
            del k[0]
            del find[0]
 
 
 
 
 
 
for i in range(time):
    a,b = map(int,sys.stdin.readline().split(" "))
    k = list(map(int, sys.stdin.readline().rstrip().split(" ")))
    find = [0]*len(k)
    find[b]='find'
 
    print(check(k,find))
 
 
728x90

+ Recent posts