fork download
  1. def fn():
  2. n = int(input())
  3. matrix = []
  4. for i in range(1,n+1):
  5. line = input().split(" ")
  6. a, b = int(line[0]), int(line[1])
  7. matrix.append([a,b])
  8. print(matrix)
  9. matrix = sorted(matrix, key = lambda x: x[1])
  10. curr = matrix[0][1]
  11. count = 1
  12. for i in range(1, n):
  13. if matrix[i][0]>=curr:
  14. curr = matrix[i][1]
  15. count+=1
  16. print(count)
  17. fn()
Success #stdin #stdout 0.05s 9608KB
stdin
10
5 14
14 17
8 13
13 15
15 17
3 6
4 7
6 9
11 14
10 11
stdout
[[5, 14], [14, 17], [8, 13], [13, 15], [15, 17], [3, 6], [4, 7], [6, 9], [11, 14], [10, 11]]
5