[백준] 19598번 최소 회의실 개수

거북이·2023년 10월 15일
0

백준[골드5]

목록 보기
81/82
post-thumbnail

💡문제접근

  • 우선순위 큐를 활용한 최소 회의실 개수 문제다.

💡코드(메모리 : 49876KB, 시간 : 288ms)

import heapq
import sys
input = sys.stdin.readline

N = int(input())
timetable = []
heap = []
for _ in range(N):
    S, T = map(int, input().strip().split())
    timetable.append([S, T])
timetable.sort(key=lambda x : x[0])
heapq.heappush(heap, timetable[0][1])

for i in range(1, N):
    if heap[0] > timetable[i][0]:
        heapq.heappush(heap, timetable[i][1])
    else:
        heapq.heappop(heap)
        heapq.heappush(heap, timetable[i][1])
print(len(heap))

💡소요시간 : 27m

0개의 댓글