개발자 톡

연습문제 톡 택배 마스터 광우

Python TC 2번 반례 부탁 드립니다. (_ _)

등록일
2024-08-03 01:09:13
조회수
104
작성자
jh0152park

Softeer라는걸 접한지 이틀? 사흘? 정도 됐는데 문제가 엄청 좋은거같습니다.

코딩테스트 공부를 안한지 몇년되어서 다 까먹어서 다시 공부를 시작하려니 반례 생각하는것도 쉽지가 않네요ㅠ.ㅠ


혹시 아래 제 코드 관련해서 반례 부탁드립니다!


감사합니다!


import sys
import itertools


def compute_work_weight(N, M, K, weights):
    work = 0
    total_weight = 0
    current_weight = 0

    index = 0
    #[5, 8, 10, 19, 7]
    while work != K:
        weight = weights[index]
        index = (index + 1) % N

        if current_weight + weight > M:
            total_weight += current_weight
            current_weight = weight
            work += 1
        else:
            current_weight += weight
    
    return total_weight


def min_weight_to_work(N, M, K, weights):
    min_weight = 999

    for perm in itertools.permutations(weights):
        weight = compute_work_weight(N, M, K, perm)
        min_weight = min(min_weight, weight)

    return min_weight



N, M, K = map(int, sys.stdin.readline().strip().split())
weights = list(map(int, sys.stdin.readline().strip().split()))


print(min_weight_to_work(N, M, K, weights))
#택배_마스터_광우

이 카테고리의 톡 더보기