practivceAlgorithm/백준

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

findTheValue 2021. 7. 24. 12:48

워낙 유명한 문제. 사용중인 회의실의 end시간기준 최소힙을 만들어 start기준 오름차순 정렬된 input과 비교하면 간단히 풀린다.

import sys
input = sys.stdin.readline
from heapq import heappop,heappush

N = int(input())
meeting_schedule = [list(map(int,input().split())) for _ in range(N)]
meeting_schedule.sort()

cnt = 0
heap = []
for start,end in meeting_schedule:
    if not heap or heap[0] > start :
        cnt +=1
        heappush(heap,end)
    else:
        heappop(heap)
        heappush(heap,end)

print(cnt)

'practivceAlgorithm > 백준' 카테고리의 다른 글

[백준][Python] 11048 이동하기  (0) 2021.07.24
[백준][Python] 14912 숫자빈도수  (0) 2021.07.24
[백준][Python] 11404 플로이드  (0) 2021.07.24
[백준][Python] 5430 AC  (0) 2021.07.24
[백준][Python] 11657 타임머신  (0) 2021.07.24