classSolution:defkSmallestPairs(self,nums1: List[int],nums2: List[int],k:int) -> List[List[int]]: heap = []for num1 in nums1:for num2 in nums2: heapq.heappush(heap, (-num1-num2, num1, num2))iflen(heap)> k: heapq.heappop(heap) res = []for i in heap: res.append([i[1], i[2]])return res
classSolution:defkSmallestPairs(self,nums1: List[int],nums2: List[int],k:int) -> List[List[int]]: heap = []for i, num1 inenumerate(nums1): heapq.heappush(heap, [num1+nums2[0], i, 0]) res = []while heap andlen(res)< k:sum, i, j = heapq.heappop(heap) res.append([nums1[i], nums2[j]])if j +1<len(nums2): heapq.heappush(heap, [nums1[i] + nums2[j +1], i, j +1])return res