본문 바로가기

알고리즘 문제풀이

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

https://www.acmicpc.net/problem/19598

 

heapq를 이용해서 진행되고 있는 강의 중에서 제일 먼저 종료되는 강의들을 찾아내면 된다. 

import heapq 
n = int(input()); total = 1; lastend=0 
heap =[]; arr =[] 
for i in range(n):
    a,b = map(int, input().split())
    arr.append((a,b))
arr.sort() 
heapq.heapify(heap)
heapq.heappush(heap, arr[0][1]) 
for start,end in arr[1:] :
    lastend = heapq.heappop(heap) 
    if lastend<= start :
        # lastend = end 
        total+=0 
    else:
        heapq.heappush(heap,lastend)
        total+=1
    heapq.heappush(heap, end) 
print(total)

'알고리즘 문제풀이' 카테고리의 다른 글

무한 수열[백준 1351]  (0) 2025.01.07
국왕의 방문[백준 2982]  (0) 2025.01.05
컵라면 [백준 1781]  (0) 2024.09.30
URLs [백준 6324]  (0) 2024.09.23
Šifra [백준 20959]  (0) 2024.09.22