반응형
using System;
using System.Linq;
public class Solution {
public int solution(int k, int m, int[] score) {
var boxCount = score.Length / m;
var orderedScore = score.OrderByDescending(x => x).ToList();
int sum = 0;
for(int i = 0; i < boxCount; i++) {
int a = orderedScore.Skip(m*i).Take(m).Min();
int b = a * m;
sum += b;
}
return sum;
}
}
단순히 점수의 배열을 내림차순 또는 오름차순으로 정렬한 후, m개씩 Take하면서 곱해주면서 더해주면 되는 간단한 문제입니다.
사실 Linq안쓰고 System.Array의 Array 클래스들을 쓰면 됩니다...
https://learn.microsoft.com/ko-kr/dotnet/api/system.array?view=net-8.0&redirectedfrom=MSDN
Array Class (System)
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.
learn.microsoft.com
반응형
'알고리즘 > 프로그래머스' 카테고리의 다른 글
프로그래머스 - 단어 변환 (C++) (0) | 2025.02.16 |
---|---|
프로그래머스 - 택배 상자 꺼내기 (C++) (1) | 2025.02.16 |
프로그래머스 - 피로도 (C++) (0) | 2025.02.15 |
프로그래머스 - 불량 사용자 (C++) (0) | 2025.02.15 |
[프로그래머스] (C#) 공원 산책 (1) | 2024.06.04 |