Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Save all visited sums and corresponding indexes in a priority queue. Then, once you pop the smallest sum so far, you can quickly identify the next m candidates for smallest sum by incrementing each row index by 1.