import heapqdef min_k_pair_sum(array1, array2, k):if not array1 or not array2 or k == 0:return 0heap = visited = set# 初始时,最小的组合是array1[0] + array2[0]heapq.heappush(heap, (array1[0] + array2[0], 0, 0))visited.add((0, 0))result = 0for _ in range(k):if not heap:breakcurrent_sum, i, j = heapq.heappop(heap)result += current_sum# 尝试将i+1,j的组合加入堆if i + 1摘要:import heapqdef min_k_pair_sum(array1, array2, k):if not array1 or not array2 or k == 0:return 0heap = visited = set# 初始时,最小的组合是ar
来源:小可课堂