Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions JHLEE325/202508/03 BOJ G5 강의실 배정.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
```java
import java.io.*;
import java.util.*;

public class Main {
static class study implements Comparable<study> {
int start, end;

study(int s, int e) {
start = s;
end = e;
}

@Override
public int compareTo(study o) {
if (this.start != o.start)
return Integer.compare(this.start, o.start);
return Integer.compare(this.end, o.end);
}
}

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int N = Integer.parseInt(br.readLine());

study[] studies = new study[N];
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
int s = Integer.parseInt(st.nextToken());
int e = Integer.parseInt(st.nextToken());
studies[i] = new study(s, e);
}

Arrays.sort(studies);

PriorityQueue<Integer> pq = new PriorityQueue<>();
pq.add(studies[0].end);

for (int i = 1; i < N; i++) {
int curStart = studies[i].start;
int curEnd = studies[i].end;
if (!pq.isEmpty() && pq.peek() <= curStart) {
pq.poll();
}
pq.add(curEnd);
}

System.out.println(pq.size());
}
}
```