Softeer 택배 마스터 광우 (난이도 3)

Yibangwon·2022년 8월 12일
0

알고리즘 문제풀이

목록 보기
49/60


정답 코드

from itertools import permutations

def solution(r, k, m, n):
    cnt, temp, bag = -1, 0, 0
    for i in range(k):
        while temp <= m:
            cnt = (cnt + 1) % n
            temp += r[cnt]
        temp -= r[cnt]
        cnt -= 1
        bag += temp
        temp = 0

    return bag

N, M, K = map(int, input().split())
box = list(map(int, input().split()))

rails = list(permutations(box))

ans = []

for r in rails:
    ans.append(solution(r, K, M, N))

print(min(ans))

알고리즘 유형

brute force

배운 점

permutation

profile
I Don’t Hope. Just Do.

0개의 댓글