GREEDY 一波带走,直接用左下标排序,然后贪心时刻保持最大的右边界,如果最大右边界不触及新的区间,则区间个数+1,并同时更新 最右边界
n = int(input())
ans = 0
right = - float("inf")
a = []
for i in range(n):
l, r = map(int, input().split())
a.append([l, r])
a.sort()
for i in range(n):
l, r = a[i][0], a[i][1]
if l > right:
ans += 1
right = r
else:
right = max(right, r)
print(ans)