콘솔창 & 윈도우창/코딩 테스트

프로그래머스 LV.1 과일 장수

뽀또치즈맛 2024. 11. 5. 09:57

 
 
https://school.programmers.co.kr/learn/courses/30/lessons/135808?language=cpp
 

#include <string>
#include <vector>
#include <iostream>
#include <algorithm>


using namespace std;

int solution(int k, int m, vector<int> score) {
    int answer = 0;
    vector<vector<int>> boxScore;
    int repetition = score.size() / m;

    sort(score.rbegin(), score.rend());

    for (int i = 0; boxScore.size() <= repetition; i += m) {
        vector<int> t;
        if (i + m > score.size()) break;
        for (int j = i; j < i + m; j++) {
            t.push_back(score[j]);
        }
        boxScore.push_back(t);
    }

    for (int i = 0; i < boxScore.size(); i++) {
        answer += m * boxScore[i][boxScore[i].size() - 1];
    }

    return answer;
}