[프로그래머스] 과일 장수 (Python)

Minyoung Lee·2023년 1월 12일

Programmers

목록 보기
13/15
post-thumbnail

문제 링크

https://school.programmers.co.kr/learn/courses/30/lessons/135808#

코드

def solution(k, m, score):
    answer = 0
    score = sorted(score, reverse=True)
    
    if len(score) < m:
        return 0
    else:
        for i in range(m-1, len(score) ,m):
            answer += (score[i] * m)
            
        return answer

계속 시간 에러로 테케 11-15가 안됐는데

  • 이전 코드
    • 반복문 while(-> 위처럼 for 문으로 제한 해도 안됨)
    • min(가장 최소값 계산) or del/pop으로 score 자체를 수정하고 그 다음 값을 빼서 계산했는데도 시간 에러

아예 값 수정도 안하고 인덱스로 가장 작은 값을 뽑아서 하니까 통과.

profile
웩알고👩‍💻

0개의 댓글