Skip to content

Commit 14976af

Browse files
authored
[20251004] BOJ / G5 / 강의실 / 김수연
[20251004] BOJ / G5 / 강의실 / 김수연
2 parents 93bd933 + c665d61 commit 14976af

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 boj1374 {
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int n = Integer.parseInt(br.readLine());
9+
Lecture[] arr = new Lecture[n];
10+
for (int i = 0; i < n; i++) {
11+
StringTokenizer st = new StringTokenizer(br.readLine());
12+
st.nextToken();
13+
int start = Integer.parseInt(st.nextToken());
14+
int end = Integer.parseInt(st.nextToken());
15+
arr[i] = new Lecture(start, end);
16+
}
17+
Arrays.sort(arr, (o1, o2) -> o1.start - o2.start);
18+
PriorityQueue<Lecture> pq = new PriorityQueue<>();
19+
pq.add(arr[0]);
20+
for (int i = 1; i < n; i++) {
21+
Lecture current = pq.peek();
22+
if (current.end <= arr[i].start) {
23+
pq.poll();
24+
current.end = arr[i].end;
25+
pq.add(current);
26+
} else {
27+
pq.add(arr[i]);
28+
}
29+
30+
}
31+
System.out.println(pq.size());
32+
33+
}
34+
35+
36+
public static class Lecture implements Comparable<Lecture> {
37+
int start;
38+
int end;
39+
40+
public Lecture(int start, int end) {
41+
this.start = start;
42+
this.end = end;
43+
}
44+
45+
@Override
46+
public int compareTo(Lecture o) {
47+
if (this.end == o.end) return this.start - o.start;
48+
return this.end - o.end;
49+
}
50+
}
51+
}
52+
```

0 commit comments

Comments
 (0)