알고리즘

백준 13335번 : 트럭(Python)

jenyy 2021. 4. 7. 20:24

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

from collections import deque

def solution():
    time = 0
    while len(data)!=0 or sum(a)!=0:
        a[0] = 0
        a.rotate(-1)

        if len(data)!=0 and (sum(a) + data[0]) <= l:
            number = data.pop(0)
            a[w - 1] = number
        time += 1
    return time

n,w,l = map(int,input().split())
data = list(map(int,input().split()))
a = deque([0]*w)
print(solution())