Skip to content

Commit c05979a

Browse files
committed
[Gold V] Title: 강의실, Time: 528 ms, Memory: 48580 KB -BaekjoonHub
1 parent 216d093 commit c05979a

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# [Gold V] 강의실 - 1374
2+
3+
[문제 링크](https://www.acmicpc.net/problem/1374)
4+
5+
### 성능 요약
6+
7+
메모리: 48580 KB, 시간: 528 ms
8+
9+
### 분류
10+
11+
자료 구조, 그리디 알고리즘, 우선순위 큐, 정렬
12+
13+
### 제출 일자
14+
15+
2025년 5월 15일 00:17:41
16+
17+
### 문제 설명
18+
19+
<p>N개의 강의가 있다. 우리는 모든 강의의 시작하는 시간과 끝나는 시간을 알고 있다. 이때, 우리는 최대한 적은 수의 강의실을 사용하여 모든 강의가 이루어지게 하고 싶다.</p>
20+
21+
<p>물론, 한 강의실에서는 동시에 2개 이상의 강의를 진행할 수 없고, 한 강의의 종료시간과 다른 강의의 시작시간이 겹치는 것은 상관없다. 필요한 최소 강의실의 수를 출력하는 프로그램을 작성하시오.</p>
22+
23+
### 입력
24+
25+
<p>첫째 줄에 강의의 개수 N(1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개의 줄에 걸쳐 각 줄마다 세 개의 정수가 주어지는데, 순서대로 강의 번호, 강의 시작 시간, 강의 종료 시간을 의미한다. 강의 번호는 1부터 N까지 붙어 있으며, 입력에서 꼭 순서대로 주어지지 않을 수 있으나 한 번씩만 주어진다. 강의 시작 시간과 강의 종료 시간은 0 이상 10억 이하의 정수이고, 시작 시간은 종료 시간보다 작다.</p>
26+
27+
### 출력
28+
29+
<p>첫째 줄에 필요한 최소 강의실 개수를 출력한다.</p>
30+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import heapq
2+
import sys
3+
input = sys.stdin.readline
4+
5+
start_heap = []
6+
end_heap = []
7+
room = 0
8+
9+
for _ in range(int(input())):
10+
n, start, end = map(int, input().split())
11+
heapq.heappush(start_heap, (start, end))
12+
13+
while start_heap:
14+
start, end = heapq.heappop(start_heap)
15+
16+
while end_heap and end_heap[0][0] <= start:
17+
heapq.heappop(end_heap)
18+
19+
heapq.heappush(end_heap, (end, start))
20+
room = max(room, len(end_heap))
21+
22+
print(room)

0 commit comments

Comments
 (0)