list를 que처럼 사용하여 풀기
def solution(bridge_length, weight, truck_weights):
answer = 0
tot=0
que_i=0
que=[0]*bridge_length
for truck_weight in truck_weights:
tot-=que.pop(0) #맨 앞에 que값 다리를 건넘
while(tot+truck_weight>weight): #다리에 있는 트럭 무게가 weight보다 클경우
que.append(0) #0을 추가시키고
answer+=1
tot-=que.pop(0) #맨 앞에 que값 빼기
tot+=truck_weight
que.append(truck_weight) #que맨뒤에 트럭의 무게 넣기
answer+=1
answer+=bridge_length #맨 뒤의 truck_weight값 다리를 지나기 위해 걸리는 시간
return answer
'algorithm > coding test' 카테고리의 다른 글
프로그래머스 - 큰수만들기 (파이썬) (0) | 2024.04.15 |
---|---|
프로그래머스 - 2xn타일링 (파이썬) (0) | 2024.04.15 |
프로그래머스 - 택배상자 (파이썬) (0) | 2024.04.14 |
프로그래머스 - 숫자변환하기 (파이썬) (0) | 2024.04.14 |
프로그래머스 - 호텔 대실 (파이썬) (0) | 2024.04.14 |