Untitled
unknown
plain_text
2 years ago
1.1 kB
8
Indexable
def earliest_finish_time(comedy_release, comedy_duration, drama_release, drama_duration):
# Combine comedy and drama movies along with their release times and durations
events = [(time, 'comedy', duration) for time, duration in zip(comedy_release, comedy_duration)] + \
[(time, 'drama', duration) for time, duration in zip(drama_release, drama_duration)]
# Sort events by release time
events.sort()
# Initialize variables to track the earliest finish time
earliest_time = float('inf')
comedy_end_time = drama_end_time = 0
# Iterate through all events
for release_time, category, duration in events:
if category == 'comedy':
# Calculate the finish time for the comedy movie
comedy_end_time = max(comedy_end_time, release_time) + duration
else:
# Calculate the finish time for the drama movie
drama_end_time = max(drama_end_time, release_time) + duration
# Update the earliest finish time considering overlapping times
earliest_time = min(earliest_time, max(comedy_end_time, drama_end_time))
return earliest_timeEditor is loading...
Leave a Comment