Skip to content

Commit c67ebc6

Browse files
authored
[20250903] PGM / LV3 / 디스크 컨트롤러 / 김수연
1 parent 961bca3 commit c67ebc6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'''java
2+
import java.util.*;
3+
class Solution {
4+
public int solution(int[][] jobs) {
5+
int answer = 0;
6+
jobs.add(new int[]{1, 1});
7+
Arrays.sort(jobs, (o1, o2) -> Integer.compare(o1[0], o2[0]));
8+
PriorityQueue<int[]> pq = new PriorityQueue<>((o1, o2) -> Integer.compare(o1[0], o2[0]));
9+
int curr_time = 0;
10+
int curr_idx = 0;
11+
int cnt = 0;
12+
while (cnt < jobs.length) {
13+
while (curr_idx < jobs.length && jobs[curr_idx][0] <= curr_time) {
14+
pq.add(new int[]{jobs[curr_idx][1], jobs[curr_idx][0]}); //(걸리는 시간, 시작 시간)
15+
curr_idx += 1;
16+
}
17+
if (!pq.isEmpty()) {
18+
int[] time = pq.poll();
19+
cnt += 1;
20+
answer += (curr_time - time[1] + time[0]);
21+
curr_time += time[0];
22+
} else {
23+
curr_time += 1;
24+
}
25+
}
26+
return answer / jobs.length;
27+
}
28+
}
29+
```

0 commit comments

Comments
 (0)