Skip to content

Commit 298c832

Browse files
committed
[BOJ] #1374. 강의실 / 골드5 / 30분 / 힌트 -> 성공
1 parent 3e4f36f commit 298c832

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
import heapq
3+
input = sys.stdin.readline
4+
5+
n = int(input())
6+
rooms = []
7+
8+
# 강의 정보 입력받기
9+
for _ in range(n):
10+
no, start, end = map(int, input().split())
11+
rooms.append((start, end))
12+
13+
# 시작 시간 기준으로 정렬
14+
rooms.sort()
15+
16+
# 최소 힙 초기화
17+
min_heap = []
18+
19+
for start, end in rooms:
20+
# 현재 강의가 가장 빨리 끝나는 강의 이후 시작하면 해당 강의 종료
21+
if min_heap and min_heap[0] <= start:
22+
heapq.heappop(min_heap)
23+
heapq.heappush(min_heap, end)
24+
25+
# 필요한 최소 강의실 개수는 힙의 크기
26+
print(len(min_heap))

0 commit comments

Comments
 (0)