[프로그래머스] 과일 장수 python

Doyeon Kim·2024년 2월 10일

코딩테스트 공부

목록 보기
162/171

문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/135808


내림차순으로 정렬한 후 앞에서 부터 n개만큼 끊고
m개씩 나눈 사과를 (가장 작은 값 * m)로 계산해서 계속 더해주면 된다.

def solution(k, m, score):
    answer = 0
    s = sorted(score,reverse =True)
    for i in range(0,len(s), m):
        tmp = s[i:i+m]
        if len(tmp) == m:
            answer += min(tmp) *m
    return answer
profile
성장하고 도전하는 개발자. 프로그래밍 좋아하세요?

0개의 댓글