def assign_jobs(n_workers, jobs): result = [] # create a workers minHeap with all workers available at time == 0 minHeap = Heap.Min_Heap() for i in range(n_workers): minHeap.Insert( (0, i)) # insert the tuple (next_available_time, worker) # check all jobs, get the first available worker from the Heap and add the new time to the Heap for job in jobs: time, worker = minHeap.ExtractMin() # print('w,t: ', worker, time) result.append(AssignedJob(worker, time)) minHeap.Insert((time + job, worker)) return result
def main(): n = int(input()) data = list(map(int, input().split())) assert len(data) == n data2 = list(data) swaps = build_heap_naive(data) print(len(swaps)) for i, j in swaps: print(i, j) print('building minHeap . . .') minHeap = Heap.Min_Heap() swaps = minHeap.BuildHeap(data2) print(len(swaps)) for i, j in swaps: print(i, j) with open("output.txt", "w") as f: print(len(swaps), file=f) for i, j in swaps: print(i, j, file=f)