2022 하반기/Python

백준 1931 Python

concho 2023. 2. 8. 18:50

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

 

1931번: 회의실 배정

(1,4), (5,7), (8,11), (12,14) 를 이용할 수 있다.

www.acmicpc.net

 

 

import sys

n = int(sys.stdin.readline())

cnt = 1
time = []
for i in range(n):
    time.append( list(map(int, sys.stdin.readline().split())) )

time.sort(key= lambda x : (x[1],x[0]))

tm = time[0][1]
for i in range(1,n):
    if tm <= time[i][0]:
        cnt += 1
        tm = time[i][1]
        
print(cnt)

time list를 끝, 시작 순서의 중요도로 오름차순 정리

이후 끝이 다음 시작보다 크면 넘어가고 아니면 cnt++