본문 바로가기
Study/Coding Test

[백준] 11000 - 강의실 배정 Python

by 들숨날숨흡 2023. 5. 22.
728x90

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

 

11000번: 강의실 배정

첫 번째 줄에 N이 주어진다. (1 ≤ N ≤ 200,000) 이후 N개의 줄에 Si, Ti가 주어진다. (0 ≤ Si < Ti ≤ 109)

www.acmicpc.net

import heapq
import sys

input = sys.stdin.readline

N = int(input())
course = list()
answer = 1

for i in range(N):
    S, T = map(int, input().split())
    course.append((S, T))

course.sort()
classroom = list()
heapq.heappush(classroom, course[0][1])

for i in range(1, N):
    compare = course[i]
    nearest_class = heapq.heappop(classroom)
    if nearest_class <= compare[0]:
        heapq.heappush(classroom, compare[1])
    else:
        heapq.heappush(classroom, nearest_class)
        heapq.heappush(classroom, compare[1])
        answer += 1

print(answer)

 

 

 

728x90