practivceAlgorithm/백준
[백준][Python] 1817 짐챙기는 숌
findTheValue
2021. 10. 7. 08:42
책을 순서대로 쌓으므로 그디리하게 풀어야합니다.
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
weights = list(map(int, input().split()))
box, cnt = M, 1
for weight in weights:
if box - weight >= 0:
box -= weight
else:
cnt += 1
box = M - weight
if not N: cnt = 0
print(cnt)