일기 대신 코드 슬쩍

[그리디][파이썬][백준]1931번 회의실배정 본문

코딩테스트/백준(Python)

[그리디][파이썬][백준]1931번 회의실배정

코코자 2023. 3. 30. 11:56
#백준 1931번 회의실 배정
n = int(input())
time = []
for i in range(n):
    start,end = map(int,input().split())
    time.append([start, end])
count = 0
time.sort(key=lambda x: (x[0],x[1]))
now = time[0]

for i in range(1,len(time)):
    if now[1] <= time[i][0] or now[1] >= time[i][1]:
        now = time[i]
        count += 1



print(count)

반례 좀 찾아줘요,, 계속 틀림

#백준 1931번 회의실 배정
n = int(input())
time = []
for i in range(n):
    start,end = map(int,input().split())
    time.append([start, end])
count = 0 # 회의 개수를 저장
last = 0 # 회의의 마지막 시간 저장
time.sort(key=lambda x: (x[1],x[0]))

for i,j in time:
    if i>= last:
        count += 1
        last = j
print(count)

lambda….. 잘 알아야겠다….