practivceAlgorithm/swexpertacademy

[SWEA][Python] 5202 화물도크

findTheValue 2021. 9. 28. 03:32

웰노운. 빨리 끝나는 순으로 정렬 후 시작점과 비교해주며 작업 할당(그리디)

 

for test in range(1, int(input()) + 1):
    N = int(input())
    works = [tuple(map(int, input().split())) for _ in range(N)]
    works.sort(key=lambda x: (x[1], x[0]))
    last_finish = 0
    cnt = 0
    for s, e in works:
        if s >= last_finish:
            last_finish = e
            cnt += 1
    print(f'#{test} {cnt}')