회전하는 큐
Updated:
- 리스트만 사용해서
- 리스트의 remove method
N, M = map(int,input().split())
lists = []
for i in range(0,N+1):
lists.append(i)
arr = list(map(int,input().split()))
idx = 1
sum = 0
for i in arr:
tmp = lists.index(i)
min = 0
type = "right"
if tmp >= idx:
min = tmp - idx
if min > len(lists) - tmp + idx -1:
min = len(lists) - tmp + idx -1
else:
min = len(lists) - idx +tmp -1
if min > idx - tmp:
min = idx - tmp
idx = lists.index(i)
lists.remove(i)
#print(min, idx)
#print(lists)
sum+=min
print(sum)
Leave a comment