Algorithm

과일장수 / 프로그래머스

김예나 2025. 2. 27. 18:13

 

정답

  • 역순 슬라이싱 : score[-1 : -1-m : -1] 혹은 score[-m:], 첫번째는 데이터가 반대로 흘러가서 역방향으로 조회됨
  • 리스트에서 해당 범위를 삭제 : del a[start:end]
def solution(k, m, score):
    score.sort() # 오름차순 정렬
    ans = 0

    while len(score) >= m:
        s = score[-m:]
        del score[-m:]
        ans = ans + s[0] * m
    return ans