Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import cmp_to_key
- def cmp(first,second):
- first_arr, first_dep = first
- second_arr, second_dep = second
- if first_dep==second_dep:
- if first_arr==second_arr:
- return 0
- elif first_arr>second_arr:
- return 1
- else:
- return -1
- elif second_dep>first_arr:
- return -1
- else:
- return 1
- def meetup(arrival, departure):
- times = []
- for i,j in zip(arrival, departure):
- times.append((i,j))
- print(times)
- times = sorted(times, key=cmp_to_key(cmp))
- print(times)
- visited = [0 for i in range(len(arrival))]
- pos = 0
- for i in range(times[0][0],times[-1][1]+1):
- print(pos, times[pos])
- if times[pos][0]<=i<=times[pos][1]:
- visited[pos]=1
- pos+=1
- return sum(visited)
- arrival = [1,2,3,3,3]
- departure = [2,2,3,4,4]
- print(meetup(arrival, departure))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement