Muscardinus
디스크 컨트롤러 본문
728x90
programmers.co.kr/learn/courses/30/lessons/42627
function solution(jobs) {
let answer = 0;
let j = 0, time = 0;
const priorityQueue = [];
jobs.sort((a,b) => a[0] - b[0]);
while (j < jobs.length || priorityQueue.length) {
if (j < jobs.length && time >= jobs[j][0]) { //큐에 쌓기
priorityQueue.push(jobs[j++]);
priorityQueue.sort((a,b) => a[1] - b[1]);
continue;
}
if (priorityQueue.length) {
time += priorityQueue[0][1];
answer += time - priorityQueue[0][0];
priorityQueue.shift();
} else time = jobs[j][0];
}
return parseInt(answer / jobs.length);
}
728x90
Comments