파이썬알고리즘
백준 1931 회의실 배정 (파이썬)
zho
2024. 8. 27. 22:05
https://www.acmicpc.net/problem/1931
문제핵심
아래 두 조건을 모두 만족시키는 정렬이 필요하다.
1. 끝나는 시간으로 오름차순 (끝나는 시간이 짧을수록 회의를 많이 할 수 있기 때문에)
2. 시작하는 시간으로 오름차순
코드
n = int(input())
meet = []
for _ in range(n):
start, end = map(int, input().split())
meet.append((start, end))
meet.sort(key=lambda x: (x[1], x[0]))
time = 0
count = 0
for i in meet:
if time <= i[0]:
time = i[1]
count += 1
print(count)
어제 https://zhocoding.tistory.com/161 여기서 사용했던 lambda를 이용한 정렬을 해주면 된다.
728x90