Given two arrays A[] and B[] of the same length, the task is to find the minimum number of steps required to make all the elements of the array equal by replacing the element with the difference of the corresponding element from array B.
Note: If this is not possible print -1.
Sample input
2
5 6
4 3
Sample output
-1
5 5 7 10 5 15 2 2 1 3 5
Sample Output
8 Python solution:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# Calculate the minimum element in a
mi = min(a)
# Calculate the number of steps required
count = 0
i=0
while i<n:
if a[i] >=b[i]:
while a[i] >mi:
a[i] -= b[i]
count +=1
if a[i] < mi:
mi = a[i]
i= 0
if a[i] !=mi:
count =-1
break
i+=1
print(count)