처음에 문제이해를 잘못해서 3시간 걸렸다...
문제를 꼼꼼히 읽는 연습을 해야겠다. 최대한 상자를 팔아 넘겨야하는데 최고큰 상자 하나만 팔아넘겨버렸다;;
import java.util.*;
class Solution {
public int solution(int k, int m, int[] score) {
int answer = 0;
Integer[] scoreInteger = Arrays.stream(score).boxed().toArray(Integer[]::new);
Arrays.sort(scoreInteger,Collections.reverseOrder());
Deque <Integer> deq = new LinkedList<>();
int cnt=0;
int min =9999999;
int applecnt=0;
for(int i=0;i<scoreInteger.length;i++)
{
if(cnt<m)
{
if(min>scoreInteger[i])
{
min = scoreInteger[i];
}
cnt++;
}
if(cnt == m)
{
answer += min * m;
cnt =0;
}
// System.out.println(min + " " + m+ " " + cnt );
}
// System.out.println(min + " " + m+ " " + applecnt );
return answer;
}
}
프로그래머스 베스트 코드
import java.util.*;
class Solution {
public int solution(int k, int m, int[] score) {
int answer = 0;
Arrays.sort(score);
for(int i = score.length; i >= m; i -= m){
answer += score[i - m] * m;
}
return answer;
}
}