Skip to content

Commit 2e33f9a

Browse files
authored
[20251203] BOJ / G5 / 최소 회의실 개수 / 이준희
Jhlee325
2 parents 8a1bb8f + 3996535 commit 2e33f9a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
static class Meeting {
8+
int s, e;
9+
Meeting(int s, int e) {
10+
this.s = s;
11+
this.e = e;
12+
}
13+
}
14+
15+
public static void main(String[] args) throws Exception {
16+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
17+
int N = Integer.parseInt(br.readLine());
18+
19+
Meeting[] arr = new Meeting[N];
20+
21+
for (int i = 0; i < N; i++) {
22+
StringTokenizer st = new StringTokenizer(br.readLine());
23+
int s = Integer.parseInt(st.nextToken());
24+
int e = Integer.parseInt(st.nextToken());
25+
arr[i] = new Meeting(s, e);
26+
}
27+
28+
// 시작 시간 기준 정렬
29+
Arrays.sort(arr, (a, b) -> a.s - b.s);
30+
31+
// 종료 시간을 저장하는 최소 힙
32+
PriorityQueue<Integer> pq = new PriorityQueue<>();
33+
34+
for (int i = 0; i < N; i++) {
35+
int start = arr[i].s;
36+
int end = arr[i].e;
37+
38+
// 이미 끝난 회의는 회의실 재사용
39+
if (!pq.isEmpty() && pq.peek() <= start) {
40+
pq.poll();
41+
}
42+
43+
pq.offer(end);
44+
}
45+
46+
System.out.println(pq.size());
47+
}
48+
}
49+
```

0 commit comments

Comments
 (0)