본문 바로가기
카테고리 없음

[백준] 2839 설탕배달 Python 풀이

by 자작나무독자 2025. 10. 29.
import sys

input = sys.stdin.readline
N = int(input().rstrip())

arr = [3, 5]

d = [5001] * (N + 1)

d[0] = 0

for i in range(N + 1):
    for weight in arr:
        if i >= weight:
            if d[i - weight] != 5001:
                d[i] = min(d[i], d[i - weight] + 1)
if d[N] == 5001:
    print(-1)
else:
    print(d[N])