If k is very close to 1 or N, any algorithm that generates the sorted sums lazily can simply be executed until the kth or Nkth element pops up.
In particular, I am thinking about the first search for the following space: (a, b) means the element ath from A, the first list added to bth from B, the second.
Keep the best = lowest priority (a, b) pairs with the cost (a, b) = A [a] + B [b].
Start with just (1,1) in the priority queue, which is minimal.
Repeat until k items popped: pop the top (a,b) if a<|A|, push (a+1,b) if a=1 and b<|B|, push (a,b+1)
This gives you the ability to connect the comb to the pill and eliminates the need to mark each (a, b) visited in the array. Note that cost (a + 1, b)> = cost (a, b) and cost (a, b + 1)> = cost (a, b), because A and B are sorted.
Here is an image of a ridge to show the successor generation rule above (you start in the upper left corner, and - in the horizontal direction):
|------- |------- |-------
This is simply the best research (before) of all | A | * | B | tuples and their amounts.
Note that the most likely elements pressed before popping k are 2 * k, because each element has 1 or 2 successors. Here is the possible state of the queue, where the items placed in the queue are marked * :
|--*---- |-*----- *-------
Everything above and to the left of the border * already displayed.
For the case of Nk<k do the same thing, but with the order of priority and reverse order of research (or just negate and change the values, get a minimum (Nk), then deny and return the answer).
See also: Sorted List of Pairwise Sums on SO or Open Problem Design .