๐Ÿ—๏ธ Algorithm/๐ŸŸฉ ๋ฐฑ์ค€

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver1] 13335๋ฒˆ_ํŠธ๋Ÿญ

Dbswnstjd 2023. 6. 29. 17:42

๋ฌธ์ œ

https://www.acmicpc.net/problem/13335

 

13335๋ฒˆ: ํŠธ๋Ÿญ

์ž…๋ ฅ ๋ฐ์ดํ„ฐ๋Š” ํ‘œ์ค€์ž…๋ ฅ์„ ์‚ฌ์šฉํ•œ๋‹ค. ์ž…๋ ฅ์€ ๋‘ ์ค„๋กœ ์ด๋ฃจ์–ด์ง„๋‹ค. ์ž…๋ ฅ์˜ ์ฒซ ๋ฒˆ์งธ ์ค„์—๋Š” ์„ธ ๊ฐœ์˜ ์ •์ˆ˜ n (1 ≤ n ≤ 1,000) , w (1 ≤ w ≤ 100) and L (10 ≤ L ≤ 1,000)์ด ์ฃผ์–ด์ง€๋Š”๋ฐ, n์€ ๋‹ค๋ฆฌ๋ฅผ ๊ฑด๋„ˆ๋Š” ํŠธ

www.acmicpc.net

ํ’€์ด

# ๋ฐฑ์ค€ 13335๋ฒˆ ๋ฌธ์ œ - ํŠธ๋Ÿญ
n, w, l = map(int, input().split())
trucks = list(map(int, input().split()))
 
bridge = [0] * w
time = 0
 
while bridge:
    time += 1
    bridge.pop(0)
    if trucks:
        if sum(bridge) + trucks[0] <= l:
            bridge.append(trucks.pop(0))
        else:
            bridge.append(0)
print(time)