Softeer 강의실 배정 (난이도 3)

Yibangwon·2022년 7월 26일
0

알고리즘 문제풀이

목록 보기
37/60


정답 코드

import sys
import heapq

N = int(input())
lec = []
for i in range(N):
    a, b = map(int, sys.stdin.readline().split())
    heapq.heappush(lec, (b, a)) #min heap based on the end time

end = 0
ans = 0
while lec:
    l = heapq.heappop(lec)
    if end <= l[1]:
        ans += 1
        end = l[0]

print(ans)

알고리즘 유형

heap

배운 점

단순 sorting보다는 min heap을 쓰는 것이 더 빠르다

profile
I Don’t Hope. Just Do.

0개의 댓글