Algorithm/백준
[백준] 회의실 배정 - 파이썬
potato_pizza
2024. 6. 20. 23:35
728x90
회의실 배정
https://www.acmicpc.net/problem/1931
문제
코드
- 그리디를 활용한 풀이
- 끝나는 시간을 기준으로 정렬, 다음 회의 시간이 빨리 끝나는 것을 선택
# 회의실 배정
# 1931
import sys
input = sys.stdin.readline
N = int(input())
time = []
count = 1
for i in range(N):
start, end = map(int, input().split())
time.append((start, end))
time.sort(key = lambda x: (x[1], x[0]))
end = time[0][1]
for i in range(1, N):
if time[i][0] >= end:
end = time[i][1]
count += 1
print(count)
728x90
반응형