From 6259c7f2678930883fa5d762bcfe4fe77fb9a6cc Mon Sep 17 00:00:00 2001 From: Donew <47556347+03do-new30@users.noreply.github.com> Date: Fri, 18 Jul 2025 17:19:46 +0900 Subject: [PATCH] =?UTF-8?q?[20250718]=20BOJ=20/=20G5=20/=20=EA=B0=95?= =?UTF-8?q?=EC=9D=98=EC=8B=A4=20=EB=B0=B0=EC=A0=95=20/=20=EC=8B=A0?= =?UTF-8?q?=EB=8F=99=EC=9C=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\213\244 \353\260\260\354\240\225.md" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "03do-new30/202507/18 BOJ G5 \352\260\225\354\235\230\354\213\244 \353\260\260\354\240\225.md" diff --git "a/03do-new30/202507/18 BOJ G5 \352\260\225\354\235\230\354\213\244 \353\260\260\354\240\225.md" "b/03do-new30/202507/18 BOJ G5 \352\260\225\354\235\230\354\213\244 \353\260\260\354\240\225.md" new file mode 100644 index 00000000..021b6011 --- /dev/null +++ "b/03do-new30/202507/18 BOJ G5 \352\260\225\354\235\230\354\213\244 \353\260\260\354\240\225.md" @@ -0,0 +1,54 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + static int N; + static class Lecture { + int start; + int end; + + public Lecture(int start, int end) { + this.start = start; + this.end = end; + } + } + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + + Lecture[] lectures = new Lecture[N]; + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + Lecture lecture = new Lecture(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())); + lectures[i] = lecture; + } + + // 시작 시간 기준 오름차순 강의 정렬 + Arrays.sort(lectures, new Comparator() { + @Override + public int compare(Lecture o1, Lecture o2) { + return Integer.compare(o1.start, o2.start); + } + }); + + // 끝나는 시간 기준 오름차순 우선순위 큐 + PriorityQueue pq = new PriorityQueue<>(new Comparator() { + @Override + public int compare(Lecture o1, Lecture o2) { + return Integer.compare(o1.end, o2.end); + } + }); + + for (Lecture current : lectures) { + if (!pq.isEmpty() && pq.peek().end <= current.start) { + pq.poll(); // 기존 강의실 + } + pq.offer(current); + } + System.out.println(pq.size()); + br.close(); + } +} +```