[BOJ] 11000 강의실 배정 (Python)
최소힙 자료구조를 사용한다.
시작시간과 종료시간들간의 관계를 생각하면 됨
import sys
import heapq
input = sys.stdin.readline
n = int(input())
times = [list(map(int,input().split())) for _ in range(n)]
times.sort(key=lambda x: x[0])
heap = []
heapq.heappush(heap, times[0][1])
for i in range(1, n):
if heap[0] > times[i][0]:
heapq.heappush(heap, times[i][1])
else:
heapq.heappop(heap)
heapq.heappush(heap, times[i][1])
print(len(heap))
백준의 경우 입력시간 초과가 뜰 수 있기 때문에 아래와 같이 입력받는 부분을 적어준다.
import sys
input = sys.stdin.readline
스터디 자료
댓글남기기