[Softeer](LV 3) 강의실 배정

ewillwin·2023년 10월 8일
0

문제 링크

LV 3: 강의실 배정


구현 방식

  • courses를 입력받고, end를 기준으로 오름차순 정렬해주었다 (key=lambda x:(x[1], x[0]))
  • now를 현재 수업중인 수업의 종료 시각으로 두고 정렬한 courses를 순회하면서, 해당 course의 시작 시각이 now보다 크다면 1)answer++해주고 2)now를 해당 course의 종료 시각으로 update 해주는 방식으로 구현해주었다

코드

import sys

N = int(sys.stdin.readline()[:-1])
courses = []
for n in range(N):
    start, end = map(int, sys.stdin.readline().split())
    courses.append((start, end))
courses.sort(key=lambda x: (x[1], x[0]))

now = -1; answer = 0
for s, e in courses:
    if s >= now:
        answer += 1
    else: continue
    now = e

print(answer)
profile
💼 Software Engineer @ LG Electronics | 🎓 SungKyunKwan Univ. CSE

0개의 댓글