[Gold V] Title: 강의실 배정, Time: 300 ms, Memory: 62456 KB -BaekjoonHub

This commit is contained in:
SSUM
2025-04-03 14:39:35 +09:00
parent 28f78ac3e9
commit a1869b864d
2 changed files with 62 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
# [Gold V] 강의실 배정 - 11000
[문제 링크](https://www.acmicpc.net/problem/11000)
### 성능 요약
메모리: 62456 KB, 시간: 300 ms
### 분류
자료 구조, 그리디 알고리즘, 우선순위 큐, 정렬
### 제출 일자
2025년 4월 3일 14:39:21
### 문제 설명
<p>수강신청의 마스터 김종혜 선생님에게 새로운 과제가 주어졌다. </p>
<p>김종혜 선생님한테는 S<sub>i</sub>에 시작해서 T<sub>i</sub>에 끝나는 N개의 수업이 주어지는데, 최소의 강의실을 사용해서 모든 수업을 가능하게 해야 한다. </p>
<p>참고로, 수업이 끝난 직후에 다음 수업을 시작할 수 있다. (즉, T<sub>i</sub> ≤ S<sub>j</sub> 일 경우 i 수업과 j 수업은 같이 들을 수 있다.)</p>
<p>수강신청 대충한 게 찔리면, 선생님을 도와드리자!</p>
### 입력
<p>첫 번째 줄에 N이 주어진다. (1 ≤ N ≤ 200,000)</p>
<p>이후 N개의 줄에 S<sub>i</sub>, T<sub>i</sub>가 주어진다. (0 ≤ S<sub>i</sub> < T<sub>i</sub> ≤ 10<sup>9</sup>)</p>
### 출력
<p>강의실의 개수를 출력하라.</p>

View File

@@ -0,0 +1,26 @@
import sys
import heapq
input = sys.stdin.readline
n = int(input())
table = []
for _ in range(n):
start, end = map(int, input().split())
table.append((start, end))
table.sort()
rooms = []
heapq.heappush(rooms, table[0][1])
for i in range(1, n):
if table[i][0] >= rooms[0]:
heapq.heappop(rooms)
heapq.heappush(rooms, table[i][1])
print(len(rooms))