Skip to content

Commit

Permalink
solve(programmers): LV2_다리를 지나는 트럭_py
Browse files Browse the repository at this point in the history
# id: 문제 id를 숫자로 작성
# categories : 해당 문제의 유형을 ,로 구분하여 작성
# tags : 해당 문제의 태그를 ,로 구분하여 작성
# time : 해당 문제 풀이에 걸린 시간을 분단위 숫자로 작성
# try : 해당 문제에 몇번의 시도를 했는지 숫자로 작성
# help: 해당 문제에 외부의 도움을 받았는지 true/false로 작성
# url : 해당 문제의 url을 작성
id: 42583
categories: [자료구조]
tags: []
time: 240
try: 10
help: true
url: https://school.programmers.co.kr/learn/courses/30/lessons/42583
  • Loading branch information
gogumaC committed Aug 16, 2024
1 parent ee2de76 commit 8f969ea
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/programmers/LV2_다리를_지나는_트럭.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from collections import deque

def solution(bridge_length, weight, truck_weights):
time=0
q=deque()
current_w=0
for w in truck_weights:
time+=1
while q and (w+current_w>weight or time-q[0][1]==bridge_length):
out=q.popleft()
current_w-=out[0]
time=out[1]+bridge_length
q.append((w,time))
current_w+=w

time+=bridge_length

return time

def test():
#min
print(solution(1,1,[1]))

#max
print(solution(10000,10000,[10000]*10000))

#fit
print(solution(10,10,[1]*10))

# test()

0 comments on commit 8f969ea

Please sign in to comment.