if len(min_heap) == ((k-1)*(2*k-1)+1)+1: # each choice excludes at most 2k-1 candidates, we should have at least (k-1)*(2k-1)+1 candidates heapq.heappop(min_heap) return max(sum(x[0] for x in c) for c ...