Skip to content

Commit 169e9e0

Browse files
authored
Merge pull request #1001 from AlgorithmWithGod/0224LJH
[20250929] BOJ / G5 / 최소 회의실 개수 / 이종환
2 parents feea53b + f421ab1 commit 169e9e0

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.*;
6+
7+
class Main {
8+
9+
static PriorityQueue<Meeting> mPq = new PriorityQueue<>();
10+
static int size,ans;
11+
12+
static class Meeting implements Comparable<Meeting>{
13+
int start;
14+
int end;
15+
16+
17+
public Meeting (int start, int end) {
18+
this.start = start;
19+
this.end = end;
20+
}
21+
22+
@Override
23+
public int compareTo(Meeting m) {
24+
return Integer.compare(this.start, m.start);
25+
}
26+
}
27+
28+
29+
30+
public static void main(String[] args) throws NumberFormatException, IOException {
31+
init();
32+
process();
33+
print();
34+
35+
}
36+
37+
38+
public static void init() throws NumberFormatException, IOException {
39+
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
40+
size = Integer.parseInt(br.readLine());
41+
42+
for (int i = 0; i < size; i++) {
43+
StringTokenizer st = new StringTokenizer(br.readLine());
44+
int start = Integer.parseInt(st.nextToken());
45+
int end = Integer.parseInt(st.nextToken());
46+
47+
Meeting m = new Meeting(start, end);
48+
mPq.add(m);
49+
}
50+
51+
52+
}
53+
54+
public static void process() throws IOException {
55+
PriorityQueue<Integer> pq = new PriorityQueue<>();
56+
// pq에 각 회의실 사용이 끝나는 시간을 넣음 -> 가장 작은애가 지금 회의의 시작시간보다 크면 새롭게 추가. 끝.
57+
pq.add(mPq.poll().end);
58+
59+
while (!mPq.isEmpty()) {
60+
Meeting m = mPq.poll();
61+
62+
if ( pq.peek() <= m.start) {
63+
pq.poll();
64+
}
65+
pq.add(m.end);
66+
67+
68+
}
69+
ans = pq.size();
70+
71+
72+
73+
}
74+
75+
76+
public static void print() {
77+
System.out.println(ans);
78+
}
79+
}
80+
```

0 commit comments

Comments
 (0)