Advertisement
Guest User

meetup schedules

a guest
Sep 17th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. from functools import cmp_to_key
  2.  
  3. def cmp(first,second):
  4. first_arr, first_dep = first
  5. second_arr, second_dep = second
  6. if first_dep==second_dep:
  7. if first_arr==second_arr:
  8. return 0
  9. elif first_arr>second_arr:
  10. return 1
  11. else:
  12. return -1
  13. elif second_dep>first_arr:
  14. return -1
  15. else:
  16. return 1
  17.  
  18. def meetup(arrival, departure):
  19. times = []
  20. for i,j in zip(arrival, departure):
  21. times.append((i,j))
  22. print(times)
  23. times = sorted(times, key=cmp_to_key(cmp))
  24. print(times)
  25. visited = [0 for i in range(len(arrival))]
  26. pos = 0
  27. for i in range(times[0][0],times[-1][1]+1):
  28. print(pos, times[pos])
  29. if times[pos][0]<=i<=times[pos][1]:
  30. visited[pos]=1
  31. pos+=1
  32. return sum(visited)
  33.  
  34. arrival = [1,2,3,3,3]
  35. departure = [2,2,3,4,4]
  36.  
  37. print(meetup(arrival, departure))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement