使用最小堆排序任务集,贪心策略为每次加入和上一个活动时间不冲突的,结束时间最早的活动
import heapq
n = int(input())tasks = []
for _ in range(n):
a, b = map(int, input().split())
heapq.heappush(tasks, (b, a))
end = 0
count = 0
while tasks:
b, a = heapq.heappop(tasks)
if a >= end:
count += 1
end = b
print(count)