파이썬 알고리즘 문제 풀이

Baekjoon Online Judge 1931번 파이썬. 그리디.

gogi masidda 2023. 1. 9. 17:01

문제 링크
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())
I = []
for i in range(N):
  I.append(list(map(int,sys.stdin.readline().split())))
I = sorted(I,key=lambda x:x[0]) #시작시간 기준 오름차순 정렬
I = sorted(I,key=lambda x:x[1]) #종료시간 기준 오름차순 정렬

last = 0 #회의가 끝나는 시간
count = 0 #회의 개수 세기

for i,j in I:
  if i >= last:
    count += 1
    last = j

print(count)
728x90