A thief trying to escape from a jail has to cross N walls whose heights are given in arr[] each with varying heights. He climbs X feet every time. But, due to the slippery nature of those walls, every time he slips back by Y feet.  Now the task is to calculate the total number of jumps required to cross all walls and escape from the jail.
Example 1:
Input: X = 10, Y = 1, N = 1
arr = {5}
Output: 1
Explaination: He jumps 10 feet and cross 
the walls.
Example 2:
Input: X = 4, Y = 1, N = 5
arr = {6, 9, 11, 4, 5}
Output: 12
Explaination: He will have to jump 2, 3, 4, 1 
and 2 times to cross all the walls.
Your Task:
You do not need to read input or print anything. Your task is to complete the function totalJumps() which takes X, Y, N, and arr as input parameters and returns the total number of jumps to cross all the walls.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 100
X > Y
1 ≤ arr[i], X, Y ≤ 1000

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def totalJumps(self, X, Y, N, arr):

        # code here

Solutions:
class Solution:

	def totalJumps(self, X, Y, N, arr):
		numJumps = 0
		for h in arr:
			numJumps += 1
			if X < h:
				curPos = X - Y
				numJumps += 1
				while curPos + X < h:
					curPos += X - Y
					numJumps += 1
		return numJumps


class Solution:

	def totalJumps(self, X, Y, N, arr):
		c = 0
		for i in range(N):
			if arr[i] <= X:
				c += 1
			else:
				c += 1
				while arr[i] > X:
					arr[i] -= X
					arr[i] += Y
					c += 1
		return c


import math

class Solution:

	def totalJumps(self, X, Y, N, arr):
		count = 0
		for i in range(N):
			if arr[i] <= X:
				count += 1
			else:
				count += 1
				while arr[i] - X > 0:
					arr[i] = arr[i] - X + Y
					count += 1
		return count


class Solution:

	def count(self, x, y, wall):
		h = 0
		j = 0
		while j < wall:
			j += 1
			h += X
			if h >= wall:
				return j
			h -= y

	def totalJumps(self, X, Y, N, arr):
		return sum([self.count(X, Y, w) for w in arr])


class Solution:

	def totalJumps(self, X, Y, N, arr):
		n = 0
		for x in arr:
			temp = 0
			while temp < x:
				temp += X
				n += 1
				if temp < x:
					temp -= Y
		return n


class Solution:

	def totalJumps(self, x, z, n, a):
		c = 0
		for i in range(n):
			if a[i] <= x:
				c += 1
			else:
				c += 1
				while a[i] > x:
					a[i] -= x
					a[i] += z
					c += 1
		return c


class Solution:

	def totalJumps(self, X, Y, N, arr):

		def Jump(height, X, Y):
			nJumps = 1
			currHeight = X
			while currHeight < height:
				currHeight -= Y
				currHeight += X
				nJumps += 1
			return nJumps
		jumpCount = 0
		for wall in arr:
			jumpCount += Jump(wall, X, Y)
		return jumpCount


class Solution:

	def totalJumps(self, X, Y, N, arr):
		count = 0
		a = X - Y
		for i in range(N):
			if arr[i] <= X:
				count += 1
			else:
				while arr[i]:
					arr[i] -= a
					count += 1
					if arr[i] <= X:
						count += 1
						break
		return count


class Solution:

	def totalJumps(self, X, Y, N, arr):
		(s, den) = (0, X - Y)
		for i in range(N):
			while arr[i] > X:
				s += 1
				arr[i] = arr[i] - (X - Y)
			s += 1
		return s


class Solution:

	def totalJumps(self, X, Y, N, arr):
		count = 0
		for i in range(N):
			if arr[i] <= X:
				count += 1
				continue
			h = arr[i]
			while h > X:
				h = h - X + Y
				count += 1
			count += 1
		return count


class Solution:

	def totalJumps(self, X, Y, N, arr):
		jump = 0
		for i in arr:
			ht = 0
			while ht < i:
				if ht + X >= i:
					jump += 1
					break
				ht += X - Y
				jump += 1
		return jump


import math

class Solution:

	def totalJumps(self, X, Y, N, arr):
		s = 0
		for i in range(N):
			if X >= arr[i]:
				s = s + 1
				continue
			else:
				k = (arr[i] - X) // (X - Y)
				if k * (X - Y) < arr[i] - X:
					k = k + 1
				s = s + (k + 1)
		return s


import math

class Solution:

	def totalJumps(self, X, Y, N, arr):
		totJumps = 0
		jumpDist = X - Y
		for i in range(N):
			if arr[i] <= X:
				totJumps += 1
				continue
			h = arr[i]
			while h > X:
				totJumps += 1
				h = h - X + Y
			totJumps += 1
		return totJumps


class Solution:

	def totalJumps(self, X, Y, N, arr):
		jumps = 0
		for i in arr:
			if i <= X:
				jumps += 1
			else:
				jumps += (i - X) // (X - Y)
				if (i - X) % (X - Y):
					jumps += 2
				else:
					jumps += 1
		return jumps


class Solution:

	def totalJumps(self, X, Y, N, arr):
		jumps = 0
		for i in arr:
			jumps += 1
			if i > X:
				h = i - X
				temp = h // (X - Y)
				if temp * (X - Y) < h:
					jumps += 1
				jumps += temp
		return jumps


class Solution:

	def totalJumps(self, X, Y, N, arr):
		jump = 0
		for i in range(N):
			if X > arr[i]:
				jump += 1
			else:
				temp = 0
				while temp < arr[i]:
					temp = temp + X
					jump += 1
					if temp >= arr[i]:
						break
					temp = temp - Y
		return jump


class Solution:

	def totalJumps(self, X, Y, N, arr):
		ans = 0
		for i in arr:
			c = 0
			for j in range(100):
				c += X
				ans += 1
				if c >= i:
					break
				else:
					c -= Y
		return ans


class Solution:

	def totalJumps(self, x, y, N, arr):
		jumps = 0
		for i in range(N):
			if arr[i] <= x:
				jumps += 1
				continue
			h = arr[i]
			while h > x:
				jumps += 1
				h = h - (x - y)
			jumps += 1
		return jumps


class Solution:

	def totalJumps(self, X, Y, N, arr):
		a = []
		for i in arr:
			x = i
			count = 0
			while x > 0:
				count += 1
				x = x - X
				if x <= 0:
					break
				else:
					x += Y
			a.append(count)
		return sum(a)


class Solution:

	def totalJumps(self, x, y, n, height):
		jumps = 0
		for i in range(n):
			if height[i] <= x:
				jumps += 1
				continue
			h = height[i]
			while h > x:
				jumps += 1
				h = h - (x - y)
			jumps += 1
		return jumps


class Solution:

	def totalJumps(self, X, Y, N, arr):
		ts = 0
		for i in arr:
			cd = 0
			s = 0
			while True:
				s += 1
				cd += X
				if cd >= i:
					break
				cd -= Y
			ts += s
		return ts


import math

class Solution:

	def totalJumps(self, X, Y, N, arr):
		ans = 0
		for i in range(len(arr)):
			if arr[i] <= X:
				ans += 1
				continue
			t = math.ceil((arr[i] - X) / (X - Y))
			ans += t + 1
		return ans


class Solution:

	def totalJumps(self, x, y, n, arr):
		jumps = 0
		k = 0
		temp = 0
		for i in range(0, n):
			if arr[i] <= x:
				jumps += 1
			else:
				jumps += 1
				k = arr[i] - x
				temp = k // (x - y)
				if temp * (x - y) < k:
					jumps += 1
				jumps += temp
		return int(jumps)


import math

class Solution:

	def totalJumps(self, X, Y, N, arr):
		height_jumped = X - Y
		ans = 0
		for i in range(0, N):
			if arr[i] < X:
				ans += 1
				continue
			arr[i] = arr[i] - Y
			ans += math.floor(arr[i] / height_jumped)
			rem = arr[i] % height_jumped
			if rem > 0:
				ans += 1
		return ans


class Solution:

	def totalJumps(self, X, Y, N, arr):
		ans = 0
		for i in arr:
			h = i
			jumps = 0
			if h <= X:
				ans += 1
				continue
			while h > X:
				h = h - X + Y
				jumps += 1
			ans += jumps + 1
		return ans


class Solution:

	def totalJumps(self, X, Y, N, arr):
		step = X - Y
		sum_val = 0
		for i in arr:
			if i <= X:
				sum_val += 1
			elif (i - X) % step == 0:
				sum_val += (i - X) // step + 1
			else:
				sum_val += (i - X) // step + 2
		return sum_val


class Solution:

	def totalJumps(self, X, Y, N, arr):
		jumps = 0
		for i in range(N):
			if arr[i] <= X:
				jumps += 1
			else:
				jumps += 1
				k = arr[i] - X
				temp = k // (X - Y)
				if temp * (X - Y) < k:
					jumps += 1
				jumps += temp
		return jumps


class Solution:

	def totalJumps(self, X, Y, N, arr):
		jumps = 0
		for wall in arr:
			height = wall
			while height > 0:
				height -= X
				jumps += 1
				if height > 0:
					height += Y
		return jumps


class Solution:

	def totalJumps(self, X, Y, N, arr):
		c = 0
		for i in range(N):
			c += 1
			if arr[i] > X:
				h = arr[i] - X
				t = h // (X - Y)
				if t * (X - Y) < h:
					t += 1
				c += t
		return c


class Solution:

	def totalJumps(self, x, y, N, arr):
		jump = 1
		count = 0
		for i in arr:
			while True:
				i = i - x
				if i <= 0:
					break
				else:
					i = i + y
					jump += 1
			count += jump
			jump = 1
		return count
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(X, Y, N) = [int(x) for x in input().split()]
		arr = input().split()
		for i in range(N):
			arr[i] = int(arr[i])
		ob = Solution()
		print(ob.totalJumps(X, Y, N, arr))


class Solution:

	def totalJumps(self, X, Y, N, arr):
		jumps = 0
		for i in range(N):
			if arr[i] > X:
				a = arr[i]
				while a > 0:
					if a > X:
						a = a - X + Y
					else:
						a = a - X
					jumps += 1
			else:
				jumps += 1
		return jumps
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(X, Y, N) = [int(x) for x in input().split()]
		arr = input().split()
		for i in range(N):
			arr[i] = int(arr[i])
		ob = Solution()
		print(ob.totalJumps(X, Y, N, arr))


class Solution:

	def totalJumps(self, X, Y, N, arr):
		jump = 0
		for i in range(0, N):
			if arr[i] < X:
				jump += 1
				continue
			h = arr[i]
			while h > X:
				jump += 1
				h = h - (X - Y)
			jump += 1
		return jump
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(X, Y, N) = [int(x) for x in input().split()]
		arr = input().split()
		for i in range(N):
			arr[i] = int(arr[i])
		ob = Solution()
		print(ob.totalJumps(X, Y, N, arr))


class Solution:

	def totalJumps(self, X, Y, N, arr):
		c = 0
		for i in arr:
			if i <= X:
				c += 1
			else:
				d = i - X
				f = d // (X - Y)
				if d % (X - Y) != 0:
					f += 1
				c += f + 1
		return c
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(X, Y, N) = [int(x) for x in input().split()]
		arr = input().split()
		for i in range(N):
			arr[i] = int(arr[i])
		ob = Solution()
		print(ob.totalJumps(X, Y, N, arr))


class Solution:

	def totalJumps(self, X, Y, N, arr):
		steps = 0
		for i in range(N):
			if arr[i] < X:
				steps += 1
				continue
			else:
				inc = X - Y
				remainingHeight = arr[i] - X
				if remainingHeight % inc == 0:
					steps += 1 + remainingHeight // inc
				else:
					steps += 2 + remainingHeight // inc
		return steps
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(X, Y, N) = [int(x) for x in input().split()]
		arr = input().split()
		for i in range(N):
			arr[i] = int(arr[i])
		ob = Solution()
		print(ob.totalJumps(X, Y, N, arr))


import math

class Solution:

	def totalJumps(self, X, Y, N, arr):
		j = X - Y
		count = 0
		for i in arr:
			if i <= X:
				count += 1
				continue
			while i > X:
				i = i - X + Y
				count += 1
			count += 1
		return count
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(X, Y, N) = [int(x) for x in input().split()]
		arr = input().split()
		for i in range(N):
			arr[i] = int(arr[i])
		ob = Solution()
		print(ob.totalJumps(X, Y, N, arr))


import math

class Solution:

	def totalJumps(self, X, Y, N, arr):
		jumps = 0
		for i in range(len(arr)):
			if X >= arr[i]:
				jumps += 1
			else:
				dis = arr[i]
				tempjump = 0
				while dis > X:
					dis = dis - (X - Y)
					tempjump += 1
				if dis != 0:
					jumps += tempjump + 1
				else:
					jumps = tempjump
		return jumps
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(X, Y, N) = [int(x) for x in input().split()]
		arr = input().split()
		for i in range(N):
			arr[i] = int(arr[i])
		ob = Solution()
		print(ob.totalJumps(X, Y, N, arr))


class Solution:

	def totalJumps(self, x, y, N, arr):
		import math
		ans = 0
		for i in range(len(arr)):
			if arr[i] <= x:
				val = 1
			else:
				k = arr[i] - x
				val = math.ceil(k / (x - y)) + 1
			ans += val
		return ans
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(X, Y, N) = [int(x) for x in input().split()]
		arr = input().split()
		for i in range(N):
			arr[i] = int(arr[i])
		ob = Solution()
		print(ob.totalJumps(X, Y, N, arr))


class Solution:

	def totalJumps(self, X, Y, N, arr):
		jump_count = 0
		for wall in arr:
			current_height = 0
			while 1:
				current_height += X
				jump_count += 1
				if current_height >= wall:
					break
				current_height -= Y
		return jump_count


class Solution:

	def totalJumps(self, X, Y, N, arr):
		jumps = 0
		i = 0
		while i < N:
			if arr[i] < X:
				jumps += 1
			else:
				h = arr[i]
				while h > X:
					jumps += 1
					h -= X - Y
				jumps += 1
			i += 1
		return jumps


class Solution:

	def totalJumps(self, X, Y, N, arr):
		jump = 0
		for w in arr:
			rem = w
			while rem > 0:
				if rem > X:
					rem -= X - Y
					jump += 1
				else:
					rem -= X
					jump += 1
		return jump


class Solution:

	def totalJumps(self, X, Y, N, arr):
		count = 0
		for i in arr:
			while True:
				count += 1
				i -= X
				if i <= 0:
					break
				i += Y
		return count


class Solution:

	def totalJumps(self, X, Y, N, arr):
		count = 0
		for height in arr:
			if height < X:
				count += 1
			else:
				while height > X:
					count += 1
					height = height - (X - Y)
				count += 1
		return count


class Solution:

	def totalJumps(self, X, Y, N, arr):
		cnt = 0
		for i in range(N):
			if arr[i] <= X:
				cnt += 1
				continue
			t = arr[i]
			while t > X:
				cnt += 1
				t = t - X + Y
			cnt += 1
		return cnt


class Solution:

	def totalJumps(self, X, Y, N, arr):
		j = 0
		for i in range(0, N):
			r = X
			k = 1
			while r < arr[i]:
				r += X - Y
				k += 1
			j += k
		return j


class Solution:

	def totalJumps(self, X, Y, N, arr):
		ctr = 0
		for i in arr:
			while i > X:
				ctr += 1
				i = i - X + Y
			ctr += 1
		return ctr


class Solution:

	def totalJumps(self, X, Y, N, arr):
		jumps = 0
		for i in range(0, N):
			reach = X
			jump = 1
			while reach < arr[i]:
				reach += X - Y
				jump += 1
			jumps += jump
		return jumps


class Solution:

	def totalJumps(self, X, Y, N, arr):
		f = []
		d = 0
		for i in range(0, N):
			m = 0
			c = 0
			while arr[i] > m:
				c = c + 1
				m = m + X
				if arr[i] > m:
					m = m - Y
			f.append(c)
		d = sum(f)
		return d


class Solution:

	def totalJumps(self, X, Y, N, arr):
		result = 0
		for i in range(N):
			if arr[i] <= X:
				result += 1
			else:
				a = (arr[i] - X) // (X - Y)
				if (arr[i] - X) % (X - Y) != 0:
					result += a + 2
				else:
					result += a + 1
		return result


class Solution:

	def min_steps(self, X, Y, wall):
		current_climbed = 0
		jumps = 0
		while current_climbed + X < wall:
			jumps += 1
			current_climbed += X - Y
		jumps += 1
		return jumps

	def totalJumps(self, X, Y, N, arr):
		total_jumps = 0
		for wall in arr:
			jump_for_this_wall = self.min_steps(X, Y, wall)
			total_jumps += jump_for_this_wall
		return total_jumps


class Solution:

	def totalJumps(self, X, Y, N, arr):
		i = 0
		count = 0
		for i in range(len(arr)):
			k = arr[i]
			if k <= X:
				count += 1
			else:
				count += 1
				while k - X > 0:
					k = k - X + Y
					count += 1
		return count