728x90
반응형


using System;
using System.Collections.Generic;
using System.Linq;
public class Solution
{
public int solution(int k, int m, int[] score)
{
List<int> cartlist = score.ToList(); // score 값을 가져올 리스트
cartlist.Sort(); // 정렬
cartlist.Reverse(); // 높은 수부터
int answer = 0;
for (int i = 0; i < cartlist.Count / m; i++)
{
List<int> newlist = new List<int>();
for (int j = 0; j < m; j++)
{
newlist.Add(cartlist[i * m + j]); // 높은 수부터 정렬한 리스트에서 m 만큼 자름
}
int min = newlist.Min(); // 새로 잘라온 리스트에서 낮은 값을 확인
answer += m * min; // 이를 박스 포장 과 곱해주면 끝
}
return answer;
}
}
728x90
반응형
'코딩테스트' 카테고리의 다른 글
C# [프로그래머스] Lv.1 삼총사 (1) | 2024.02.06 |
---|---|
C# [프로그래머스] Lv.1 숫자 짝꿍 (1) | 2024.02.05 |
C# [프로그래머스] Lv.1 카드 뭉치 (1) | 2023.12.26 |
C# [프로그래머스] Lv.1 덧칠하기 (0) | 2023.12.26 |
C# [프로그래머스] Lv.1 개인정보 수집 유효기간 (2) | 2023.12.26 |