class Solution:
def smallestRange(self, nums: List[List[int]]) -> List[int]:
heap = []
maxValue = -10 ** 6 - 1
start, end, k = 0, 10 ** 6, len(nums)
for i in range(k):
heapq.heappush(heap, (nums[i][0], i, 0))
if maxValue < nums[i][0]:
maxValue = nums[i][0]
while len(heap) == k:
minValue, row, col = heapq.heappop(heap)
if maxValue - minValue < end - start:
start, end = minValue, maxValue
if col + 1 < len(nums[row]):
heapq.heappush(heap, (nums[row][col+1], row, col+1))
if maxValue < nums[row][col+1]:
maxValue = nums[row][col+1]
return [start, end]