Untitled
unknown
python
2 years ago
1.1 kB
6
Indexable
def elephant(n ,m ,a ,b): mass = 0 mass1 = 0 mass2 = 0 a1 = a.copy() b1 = b.copy() print(a1) for i in range(n-1): if a[i] == b[i]: continue else: ind = b.index(a[i]) num = a[ind] a[ind] = a[i] a[i] = num mass1 += m[a[i] - 1]+m[a[ind] - 1] for i in range(n-1,-1,-1): if a1[i] == b1[i]: print ("i : ", i , " a1 = ", a1[i] , "b1 = ", b1[i]) continue else: ind = b1.index(a1[i]) num = a1[ind] a1[ind] = a1[i] a1[i] = num mass2 += m[a1[i] - 1]+m[a1[ind] - 1] mass = min(mass1,mass2) return mass check = False while check == False: n = int(input("Number of elephant: ")) mi = list(map(int, input().split())) ai = list(map(int, input().split())) bi = list(map(int, input().split())) if (len(mi) == n and len(ai) == n and len(bi) == n): check = True else: print ("type value again") print(elephant(n,mi,ai,bi))
Editor is loading...