package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode.com/problems/find-k-pairs-with-smallest-sums/
 */
public class Problem373 {
    public List<int[]> kSmallestPairs(int[] nums1, int[] nums2, int k) {
        // TODO
        return new ArrayList<>();
    }

    public static void main(String[] args) {
        Problem373 prob = new Problem373();

        System.out.println(prob.kSmallestPairs(new int[]{1, 7, 11}, new int[]{2, 4, 6}, 3)); //  [1,2],[1,4],[1,6]
        System.out.println(prob.kSmallestPairs(new int[]{1, 1, 2}, new int[]{1, 2, 3}, 3)); // [1,1],[1,1]
        System.out.println(prob.kSmallestPairs(new int[]{1, 2}, new int[]{3}, 2)); // [1,3],[2,3]
    }
}

@@ -62,16 +62,48 @@
 il.List;
+%0Aimport java.util.PriorityQueue;
 %0A%0A/**%0A *
@@ -281,30 +281,28 @@
     
-// TODO%0A        return
+List%3Cint%5B%5D%3E result =
  new
@@ -325,420 +325,723 @@
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem373 prob = new Problem373();%0A%0A        System.out.println(prob.kSmallestPairs(new int%5B%5D%7B1, 7, 11%7D, new int%5B%5D%7B2, 4, 6%7D, 3)); //  %5B1,2%5D,%5B1,4%5D,%5B1,6%5D%0A        System.out.println(prob.kSmallestPairs(new int%5B%5D%7B1, 1, 2%7D, new int%5B%5D%7B1, 2, 3%7D, 3)); // %5B1,1%5D,%5B1,1%5D%0A        System.out.println(prob.kSmallestPairs(new int%5B%5D%7B1, 2%7D, new int%5B%5D%7B3%7D, 2)); // %5B1,3%5D,%5B2,3%5D
+if (nums1.length == 0 %7C%7C nums2.length == 0 %7C%7C k == 0) %7B%0A            return result;%0A        %7D%0A        PriorityQueue%3Cint%5B%5D%3E queue = new PriorityQueue%3C%3E(%0A            (a, b) -%3E Integer.compare(a%5B0%5D + a%5B1%5D, b%5B0%5D + b%5B1%5D));%0A        for (int i = 0; i %3C k && i %3C nums1.length; i++) %7B%0A            queue.add(new int%5B%5D%7Bnums1%5Bi%5D, nums2%5B0%5D, 0%7D);%0A        %7D%0A        while (k-- %3E 0 && !queue.isEmpty()) %7B%0A            int%5B%5D current = queue.remove();%0A            result.add(new int%5B%5D%7Bcurrent%5B0%5D, current%5B1%5D%7D);%0A            int idx = current%5B2%5D;%0A            if (idx == nums2.length - 1) %7B%0A                continue;%0A            %7D%0A            queue.add(new int%5B%5D%7Bcurrent%5B0%5D, nums2%5Bidx + 1%5D, idx + 1%7D);%0A        %7D%0A        return result;
 %0A   

Solve problem 373