728x90
def solution(k, m, score):
answer = 0
score.sort(reverse=True)
# 남은사과가 한 박스에 들어가는 사과가 많을때
for i in range(0,len(score),m) :
if len(score[i:i+m]) == m :
answer += min(score[i:i+m]) * m
return answer
풀이 및 회고
정렬을 하고 난 후 슬라이싱을 잘 해줘야 한다.
처음에는 슬라이싱을 2번 해서 시간초과를 겪었다 ,, ㅠ
728x90
'프로그래머스' 카테고리의 다른 글
프로그래머스 LV1 숫자 짝궁 (0) | 2024.06.27 |
---|---|
프로그래머스 LV2 2 x n 타일링 (0) | 2024.06.26 |
프로그래머스 LV 1 K 번째 수 (0) | 2024.06.26 |
프로그래머스 LV2 숫자 변환 (0) | 2024.06.26 |
프로그래머스 LV2 택배상자 (0) | 2024.06.25 |