티스토리 뷰

"""
 *packageName    : 
 * fileName       : 11000_강의실_배정_G5
 * author         : ipeac
 * date           : 2022-03-20
 * description    :
 * ===========================================================
 * DATE              AUTHOR             NOTE
 * -----------------------------------------------------------
 * 2022-03-20        ipeac       최초 생성
 """
import heapq
import sys

heap = []
n = int(sys.stdin.readline())
arr = []

for i in range(n):
      a, b = map(int, sys.stdin.readline().split())
      arr.append([a, b])

arr.sort(key=lambda x: x[0])
print("arr : %s " % arr)

# 첫 번째 강의가 끝나는 시간 추가
heapq.heappush(heap, arr[0][1])
print("heap : %s " % heap)

for i in range(1, n):
      if heap[0] > arr[i][0]:
            heapq.heappush(heap, arr[i][1])
            print("heap : %s " % heap)
      else:
            heapq.heappop(heap)
            print("heap : %s " % heap)
            
            heapq.heappush(heap, arr[i][1])
            print("heap : %s " % heap)

print(len(heap))










#

- 우선순위 큐에 대한 내용 무지

- 소스 참고 minHeap

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함