반응형
그림의 진행방향이 큐와 같아서 큐를 사용해서 문제를 풀었다
다리를 지나는 트럭의 무게들이 다리의 하중보다 작다면 다리를 지나 올 수 있다.
트럭이 다 지나갈때 까지 반복하기 때문에 while 문을 사용해서 작성했음
import sys
n, w, L = map(int, sys.stdin.readline().split()); t, wei = 0, 0
truck = (list(map(int, sys.stdin.readline().split())))
we = [0] * w
while True:
out = we.pop(0)
wei -= out; t += 1
if truck:
if wei + truck[0] <= L:
we.append(truck[0])
wei += truck[0]
truck.pop(0)
else: we.append(0)
if len(we) == 0: break
print(t)
반응형
댓글