Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/python3
- # Big Fat Indian Wedding
- import math
- import os
- import random
- import re
- import sys
- #
- # Complete the 'maxPerformances' function below.
- #
- # The function is expected to return an INTEGER.
- # The function accepts following parameters:
- # 1. INTEGER_ARRAY arrivals
- # 2. INTEGER_ARRAY durations
- #
- def isThereAConflict(arrivals_sub, durations_sub):
- start = arrivals_sub[0]
- end = arrivals_sub[0] + durations_sub[0]
- for i in range(1, len(arrivals_sub)):
- start = arrivals_sub[i]
- if start < end:
- return True
- end = start + durations_sub[i]
- return False
- def maxPerformances(arrivals, durations):
- #sorting
- zipped = list(zip(arrivals, durations))
- sorted_zipped = sorted(zipped)
- print(sorted_zipped)
- arrivals = [item[0] for item in sorted_zipped]
- durations = [item[1] for item in sorted_zipped]
- # Algo expects sorted by arrival time
- max_perf = 0
- for i in range(len(arrivals)):
- selected_arrivals = [arrivals[i]]
- selected_durations = [durations[i]]
- for j in range(i, len(arrivals)):
- if not isThereAConflict(selected_arrivals + [arrivals[j]], selected_durations + [durations[j]]):
- selected_arrivals.append(arrivals[j])
- selected_durations.append(durations[j])
- if len(selected_arrivals) > max_perf:
- max_perf = len(selected_arrivals)
- print(f'New longest sublist! Selected arrivals: {selected_arrivals}, Selected durations: {selected_durations}')
- return max_perf
- if __name__ == '__main__':
- print(maxPerformances([1, 3, 3, 5, 7], [2, 2, 1, 2, 1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement