import java.util.Arrays;
import java.util.PriorityQueue;
public class NUM42627 {
public static void main(String[] args) {
int[][] jobs = {{1, 3}, {1, 9}, {1, 6}, {20, 6}, {20, 6}, {20, 6}};
System.out.println(solution(jobs));
}
public static int solution(int[][] jobs) {
int answer = 0;
Arrays.sort(jobs, (j1, j2) -> j1[0] - j2[0]);
PriorityQueue<int[]> requests = new PriorityQueue<>((j1, j2) -> j1[1] - j2[1]);
int finish = 0; int request = 0; int now = 0;
while(finish < jobs.length) {
while(request < jobs.length && jobs[request][0] <= now) { requests.add(jobs[request++]); }
if(requests.isEmpty()) { now = jobs[request][0]; }
else {
int[] job = requests.poll();
answer += ((now += job[1]) - job[0]);
finish++;
}
}
answer = (int) Math.floor(answer / jobs.length);
return answer;
}
}
*다른 분들의 코드를 참고하여 작성했습니다