from collections import deque
def solution(N, K, durabilities):
belt = deque(durabilities)
robots = deque([False] * N)
step = 0
while True:
step += 1
belt.rotate(1)
robots.rotate(1)
robots[-1] = False
for i in range(N - 2, -1, -1):
if robots[i] and not robots[i + 1] and belt[i + 1] > 0:
robots[i] = False
robots[i + 1] = True
belt[i + 1] -= 1
robots[-1] = False
if belt[0] > 0:
robots[0] = True
belt[0] -= 1
if belt.count(0) >= K:
return step
N = 3
K = 2
durabilities = [1, 2, 1, 2, 1, 2]
print(solution(N, K, durabilities))
To embed this project on your website, copy the following code and paste it into your website's HTML: