From 8f969eaac2f9fc2ff6b4289cc49ff7b9b68a8310 Mon Sep 17 00:00:00 2001 From: yubin Date: Fri, 16 Aug 2024 16:35:42 +0900 Subject: [PATCH] =?UTF-8?q?solve(programmers):=20LV2=5F=EB=8B=A4=EB=A6=AC?= =?UTF-8?q?=EB=A5=BC=20=EC=A7=80=EB=82=98=EB=8A=94=20=ED=8A=B8=EB=9F=AD=5F?= =?UTF-8?q?py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 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 --- ...0\353\212\224_\355\212\270\353\237\255.py" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "src/programmers/LV2_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.py" diff --git "a/src/programmers/LV2_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.py" "b/src/programmers/LV2_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.py" new file mode 100644 index 0000000..63475d0 --- /dev/null +++ "b/src/programmers/LV2_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.py" @@ -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() \ No newline at end of file