[알고리즘/백준] 11000번 : 강의실 배정(python)

유현민·2022년 7월 18일
0

알고리즘

목록 보기
218/253

시작 시간과 끝나는 시간을 비교해서 푸는 문제이다.
우선순위 큐를 이용.

1. 리스트에 입력 받은 값 넣고 sort

a = sorted([list(map(int, input().split()))for _ in range(int(input()))])

2. 제일 처음 시간과 비교

  • 제일 처음 시간과 비교하여 그 값보다 작으면 강의실을 새로 만들고 크면 강의실을 만들지 않아도 된다.
import heapq
from sys import stdin

input = stdin.readline


def solution():
    a = sorted([list(map(int, input().split()))for _ in range(int(input()))])
    r = [-1]
    for s, e in a:
        if s < r[0]: # 강의실을 만든다.
            heapq.heappush(r, e)
        else: # 강의실을 만들지 않는다.
            heapq.heapreplace(r, e)
    return len(r)


if __name__ == "__main__":
    print(solution())
profile
smilegate megaport infra

0개의 댓글