def solution(bridge_length, weight, truck_weights):
in_bridge = []
second = 0
while truck_weights:
second += 1
if in_bridge and len(in_bridge) % bridge_length == 0:
in_bridge.pop(0)
temp = truck_weights.pop(0)
in_bridge.append(temp)
if sum(in_bridge) > weight:
truck_weights.insert(0, temp)
in_bridge.pop()
in_bridge.append(0)
return second+bridge_length
bridge_length = 2
weight = 1
truck_weights = [1,1]
print(solution(bridge_length, weight, truck_weights))
def solution(bridge_length, weight, truck_weights):
in_bridge = []
second = 0
sum = 0
while truck_weights:
# for i in range(3):
second += 1
if len(in_bridge) == bridge_length:
sum -= in_bridge.pop(0)
temp = truck_weights.pop(0)
in_bridge.append(temp)
sum += temp
if sum > weight:
truck_weights.insert(0, temp)
in_bridge.pop()
in_bridge.append(0)
sum -= temp
# print(sum, in_bridge)
return second+bridge_length