-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday85.py
36 lines (28 loc) · 800 Bytes
/
day85.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
#!/bin/python3
import sys
def insertionSort1(start, arr):
probe = arr[start]
changed = 0
for ind in range(start-1, -1, -1):
if arr[ind] > probe:
changed += 1
arr[ind+1] = arr[ind]
else:
arr[ind+1] = probe
break
if arr[0] > probe:
arr[0] = probe
return changed
def insertionSort2(n, arr):
res = 0
for ind in range(1, len(arr)):
res += insertionSort1(ind, arr)
#print(" ".join(map(str, arr)))
return res
def runningTime(arr):
return insertionSort2(len(arr), arr)
if __name__ == "__main__":
n = int(input().strip())
arr = list(map(int, input().strip().split(' ')))
result = runningTime(arr)
print(result)