728x90
반응형
그리디 알고리즘 문제이다. 박스 용량의 합에 박스에 들어간 책 크기의 합을 빼주면 된다 -> sum(box) - in_box
N, M = map(int, input().split())
box = list(map(int, input().split()))
book = list(map(int, input().split()))
i = j = t = in_box = 0
while i < N and j < M:
if box[i] < t+book[j]:
t = 0
i += 1
else:
in_box += book[j]
t += book[j]
j += 1
print(sum(box)-in_box)
728x90
반응형
'Agorithm > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 1568번 새(python) (0) | 2021.02.17 |
---|---|
백준 알고리즘 1551번 수열의 변화(python) (0) | 2021.02.17 |
백준 알고리즘 1392번 노래 악보(python) (0) | 2021.02.17 |
백준 알고리즘 1373번 2진수 8진수(python) (0) | 2021.02.17 |
백준 알고리즘 6491번 Perfection(python) (0) | 2021.02.17 |