๋ฌธ์
๋ฐฑ์ค ์จ๋ผ์ธ ์ ์ง - 13335๋ฒ
ํ์ด ๊ณผ์
๋ค๋ฆฌ์ ๋ฌด๊ฒ ์ ํ์ด ์์ ๋ ๋ชจ๋ ํธ๋ญ์ด ๋ค๋ฆฌ๋ฅผ ๊ฑด๋์ ๋ค๋ฅธ ์ง์ญ์ผ๋ก ๋์ด๊ฐ๋ ์ต๋จ ์๊ฐ์ ์ฐพ๋ ๋ฌธ์ ์
๋๋ค.
ํ์ฌ ๋ค๋ฆฌ์ ์กด์ฌํ๋ ๋ชจ๋ ํธ๋ญ์ ๋ฌด๊ฒ๋ฅผ ์ถ์ฒํ๊ณ ํธ๋ญ์ ์๊ฐ์ ๋ณ๋์ ๋ฐฐ์ด๋ก ๊ด๋ฆฌํด์ ๊ตฌํํ์ต๋๋ค.
์ฌ๊ธฐ์ next
๋ณ์๋ ํ์ฌ ๋ค๋ฆฌ๋ฅผ ๊ฑด๋๊ธฐ ์ํด ๋๊ธฐ์ค์ธ ํธ๋ญ์ ๋ํ๋
๋๋ค.
์ฝ๋
import sys
from collections import deque
N, W, L = list(map(int, sys.stdin.readline().split()))
weights = list(map(int, sys.stdin.readline().split()))
def solution():
goal, next = W + 1, 1
on_bridge = deque([[1, weights[0]]])
on_weight = weights[0]
answer = 1
while on_bridge:
answer += 1
for truck in on_bridge:
truck[0] += 1
if on_bridge[0][0] == goal:
on_weight -= on_bridge[0][1]
on_bridge.popleft()
if next < N and weights[next] + on_weight <= L:
on_bridge.append([1, weights[next]])
on_weight += weights[next]
next += 1
return answer
print(solution())
๋ฐ์ํ
'๐ algorithm > boj' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ 16472 - ๊ณ ๋ฅ์ด (0) | 2021.03.14 |
---|---|
BOJ 17086 - ์๊ธฐ ์์ด2 (0) | 2021.03.08 |
BOJ 6497 - ์ ๋ ฅ๋ (0) | 2021.03.08 |
BOJ 6156 - Cow Contest (0) | 2021.03.08 |
BOJ 9625 - BABBA (0) | 2021.03.08 |
๐ฌ ๋๊ธ