programmers.co.kr/learn/courses/30/lessons/42583
def solution(bridge_length, weight, truck_weights):
# time 1 => bridges [0, 7]
# time 2 => bridges [7, 0]
# time 3 => bridges [0, 4]
# time 4 => bridges [4, 5]
# time 5 => bridges [5, 0]
# time 6 => bridges [0, 6]
# time 7 => bridges [6]
# time 8 => bridges []
bridges = [0] * bridge_length
time = 0
while bridges:
time += 1
bridges.pop(0)
if truck_weights:
if sum(bridges) + truck_weights[0] <= weight:
bridges.append(truck_weights.pop(0))
else:
bridges.append(0)
return time
res = solution(2, 10, [7, 4, 5, 6])
print(res)
'programmers 알고리즘 > 구현' 카테고리의 다른 글
42626번: 더 맵게 (힙) (0) | 2020.11.04 |
---|---|
42587번: 프린터 (0) | 2020.11.04 |
기능개발 (스택/큐) (0) | 2020.11.04 |
주식가격 (스택/큐) (0) | 2020.11.03 |
베스트앨범 (해시) (0) | 2020.11.03 |