public String solution(int n, int t, int m, String[] timetable) {
int busTime = 9 * 60;
int busCount = 0;
int lastCrewTime = 0;
PriorityQueue<Integer> crew = new PriorityQueue<>();
for (String time : timetable) {
crew.add(timeToInteger(time));
}
while (busCount < n) {
if (busCount != 0)
busTime += t;
int cnt = 0;
while (!crew.isEmpty() && cnt < m) {
if (crew.peek() > busTime)
break;
if (busCount == n - 1 && cnt == m - 1) {
lastCrewTime = (crew.poll() - 1);
return String.format("%02d:%02d", lastCrewTime / 60, lastCrewTime % 60);
}
crew.poll();
cnt++;
}
busCount++;
}
return String.format("%02d:%02d", busTime / 60, busTime % 60);
}
public int timeToInteger(String time) {
String[] times = time.split(":");
return Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]);
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/17678