백준_회의실배정_1931

이하연·2021년 9월 7일
0

2021알고리즘

목록 보기
19/32

백준_회의실배정_1931

  • 정렬문제

코드

import sys
N = int(sys.stdin.readline())
conference = list()

for _ in range(N) :
    start,end = map(int,sys.stdin.readline().split(" "))
    conference.append([start,end])

conference.sort(key= lambda x:(x[1],x[0]))
standard = conference[0]
cnt = 1

for s,e in conference[1:] :
    if s < standard[1] :
        continue
    cnt+=1
    standard = [s,e]

print(cnt)

풀이

lamba x:(x[1],x[0])

  • 끝나는 시간을 오름차순 x[1]
  • 끝나는 시간이 동일하다면 → 시작시간이 더 빠른것으로 ( 오름차순 ) x[0]

결과

0개의 댓글