-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1021.py
More file actions
28 lines (27 loc) · 679 Bytes
/
1021.py
File metadata and controls
28 lines (27 loc) · 679 Bytes
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
from collections import deque
def main():
answer = 0
n, m = map(int, input().split())
arr = list(map(int, input().split()))
dq = deque()
for i in range(1, n+1):
dq.append(i)
for i in range(m):
cnt = 0
for j in range(len(dq)):
if dq[j] == arr[i]:
break
else:
cnt += 1
if cnt > len(dq)//2:
while dq[0] != arr[i]:
answer += 1
dq.rotate()
else:
while dq[0] != arr[i]:
answer += 1
dq.rotate(-1)
dq.popleft()
print(answer)
if __name__ == "__main__":
main()