# Leetcode 373 - Find K pairs with smallest sums

`Note:`

- Use
`maxPriorityQueue`

coz it’s easier to check if we need to add new pairs after`size >= k`

. - Add first
`k`

pairs. After that, if`new pairs < pq.top`

,`pop`

the top and add the new pair. - We don’t need to iterate all
`nums1`

and`nums2`

. We only need to iterate`k`

each coz then we’ll have`k**2`

in total. We can def find`k`

pairs from them.

`Question:`

You are given two integer arrays `nums1`

and `nums2`

sorted in `ascending`

order and an integer `k`

.

Define a pair `(u, v)`

which consists of one element from the first array and one element from the second array.

Return the `k`

pairs `(u1, v1), (u2, v2), ..., (uk, vk)`

with the smallest sums.

`Example:`

1 | Input: nums1 = [1,7,11], nums2 = [2,4,6], k = 3 |

`Code:`

1 | /** |