-
Notifications
You must be signed in to change notification settings - Fork 0
/
boj_1966.py
40 lines (36 loc) · 1022 Bytes
/
boj_1966.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys
from collections import deque
input = sys.stdin.readline
case_count = int(input())
res = []
for _ in range(case_count):
n, index = list(map(int, input().split(" ")))
files = list(map(int, input().split(" ")))
deq = deque(files)
cur_index = 0
count = 0
while cur_index != index:
cur_priority = deq[cur_index]
higher_priority_index = -1
for i in range(len(deq)):
if deq[i] > cur_priority:
higher_priority_index = i
break
if higher_priority_index != -1:
for j in range(higher_priority_index):
if j == index:
index += len(deq) - 1
else:
index -= 1
p = deq.popleft()
deq.append(p)
else:
deq.popleft()
index -= 1
cur_index -= 1
count += 1
res.append(count)
# print(count)
# print([n, index])
# print(files)
print(res)