✅ What I did today
⚔️ 프로그래머스
상담원 인원
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
vector<vector<int>> mentor_cases;
void RCombi_Mentor(int remain, int type, vector<int>& mentor_case)
{
if (type+1 == mentor_case.size()){
mentor_case[type] = 1+remain;
mentor_cases.push_back(mentor_case);
return;
}
for (int i = 0; i <= remain; ++i) {
mentor_case[type] = 1+i;
RCombi_Mentor(remain - i, type+1, mentor_case);
}
}
int TotalWait(vector<int>& mentor_case, vector<vector<int>>& reqs)
{
vector<priority_queue<int, vector<int>, greater<int>>> mentorq(mentor_case.size());
for (int type = 1; type < mentor_case.size(); ++type) {
int count = mentor_case[type];
while (count--) { mentorq[type].push(0); }
}
int total_wait = 0;
for (vector<int> req : reqs) {
int start = req[0];
int duration = req[1];
int type = req[2];
int mentor_end = mentorq[type].top();
mentorq[type].pop();
if (mentor_end < start) { mentorq[type].push(start + duration); }
else {
total_wait += (mentor_end - start);
mentorq[type].push(mentor_end + duration);
}
}
return total_wait;
}
int solution(int k, int n, vector<vector<int>> reqs) {
vector<int> mentor_case(k+1);
RCombi_Mentor(n-k,1,mentor_case);
int min_wait_time = 100 * 3000000;
for (vector<int> mentor_case : mentor_cases) {
min_wait_time = min(TotalWait(mentor_case,reqs),min_wait_time);
}
return min_wait_time;
}
int main()
{
vector<vector<int>> reqs1 = { {5, 55, 2} ,{10, 90, 2},{20, 40, 2},{50, 45, 2},{100, 50, 2} };
cout << solution(2, 3, reqs1);
}