Skip to content

Commit 9be56ff

Browse files
authored
Merge pull request #603 from AlgorithmWithGod/JHLEE325
[20250803] BOJ / G5 / 강의실 배정 / 이준희
2 parents a5d71c2 + d8d8241 commit 9be56ff

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
static class study implements Comparable<study> {
7+
int start, end;
8+
9+
study(int s, int e) {
10+
start = s;
11+
end = e;
12+
}
13+
14+
@Override
15+
public int compareTo(study o) {
16+
if (this.start != o.start)
17+
return Integer.compare(this.start, o.start);
18+
return Integer.compare(this.end, o.end);
19+
}
20+
}
21+
22+
public static void main(String[] args) throws IOException {
23+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
24+
StringTokenizer st;
25+
int N = Integer.parseInt(br.readLine());
26+
27+
study[] studies = new study[N];
28+
for (int i = 0; i < N; i++) {
29+
st = new StringTokenizer(br.readLine());
30+
int s = Integer.parseInt(st.nextToken());
31+
int e = Integer.parseInt(st.nextToken());
32+
studies[i] = new study(s, e);
33+
}
34+
35+
Arrays.sort(studies);
36+
37+
PriorityQueue<Integer> pq = new PriorityQueue<>();
38+
pq.add(studies[0].end);
39+
40+
for (int i = 1; i < N; i++) {
41+
int curStart = studies[i].start;
42+
int curEnd = studies[i].end;
43+
if (!pq.isEmpty() && pq.peek() <= curStart) {
44+
pq.poll();
45+
}
46+
pq.add(curEnd);
47+
}
48+
49+
System.out.println(pq.size());
50+
}
51+
}
52+
```

0 commit comments

Comments
 (0)