https://school.programmers.co.kr/learn/courses/15009/lessons/121689
import java.io.*;
import java.util.*;
class Node implements Comparable<Node>{
int start;
int end;
Node(int start , int end )
{
this.start = start;
this.end = end;
}
@Override
public int compareTo(Node now)
{
return this.start - now.start;
}
}
class Solution {
static PriorityQueue<Node>pq = new PriorityQueue<>();
static ArrayList<Node>list = new ArrayList<>();
public static void main(String[] args) {
solution(new int[]{5,12,30}, new int[]{1,2,0,1}, 10);
}
public static int solution(int[] menu, int[] order, int k) {
int start = 0;
int end = 0;
for (int i = 0; i < order.length; i++) {
start = i * k;
if(i > 0
&& list.get(i-1).end > start
) end = menu[order[i]] + start + ( list.get(i-1).end - start );
else end = menu[order[i]] + start ;
list.add(new Node(start, end));
pq.offer(new Node(start, end));
}
int max = Integer.MIN_VALUE;
int idx = 0;
while( idx < end) {
int temp = idx;
int cnt = 0;
for (int j = 0; j < list.size(); j++) {
if (list.get(j).start <= temp && temp < list.get(j).end) {
cnt++;
}
}
max = Math.max(max, cnt);
if (pq.isEmpty()) {
break;
}
idx = pq.poll().start;
}
return max;
}
}