import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
List<Integer> answer = new ArrayList<>(); // 결과 저장용 리스트
Queue<Integer> q = new LinkedList<>(); // 기능별 완료까지 필요한 날짜
// 1. 각 기능마다 완료까지 걸리는 날짜 계산
for (int i = 0; i < progresses.length; i++) {
int duration = (100 - progresses[i]) / speeds[i];
if ((100 - progresses[i]) % speeds[i] > 0) duration++; // 나머지 있으면 하루 추가
q.offer(duration); // 큐에 넣기
}
int beforeDuration = q.poll(); // 첫 번째 작업일수 기준
answer.add(1); // 첫 배포는 무조건 1개 시작
// 2. 큐 순회하며 배포 그룹 계산
while (!q.isEmpty()) {
int currentDuration = q.poll();
if (beforeDuration >= currentDuration) {
// 현재 작업도 이전 작업과 함께 배포 가능
int last = answer.get(answer.size() - 1);
answer.set(answer.size() - 1, last + 1);
} else {
// 더 오래 걸리는 작업은 새로운 배포 시작
answer.add(1);
beforeDuration = currentDuration;
}
}
// 3. 결과 리스트를 배열로 변환
return answer.stream().mapToInt(i -> i).toArray();
}
}