This is the weighted job scheduling problem in O(N log N) using dynamic programming
How each list is structured = [city, start_day, end_day, revenue]
rev = [['A', 1, 7, 5], ['B', 6, 9, 4], ['C', 1, 5, 3]]
>>> print(max_rev(rec))
['B', 6, 9, 4], ['C', 1, 5, 3]
My attempt for n log n:
- Sort the list based on the last day in a city using a modified merge sort (n log n), this will get me
[['C', 1, 5, 3], ['A', 1, 7, 5], ['B', 6, 9, 4]]number them 0 -> n according to its index now (I mentioned insertion sort before, I messed up as its worst case is n^2, hence I'm using merge sort now) - *clueless from here. Create a
memo list of n (3) sizeand each index ofmemorepresents the index position of a particular city in now sorted rev - Each index of the memo will contain the maximum revenue the salesman can obtain if he works at that city. Do this by looping through the sorted list, and for each city information, add up all the revenues between it and the cities that has a greater start_day then the selected city's end_day.