Find k maximum numbers from a heap of size n in O(klog(k)) time
Hint: Each time you perform one iteration of your loop, how much does the size of $B$ increase?  Each time you perform one iteration of your loop, how many numbers are added to $A$?

You terminate once $k$ integers have been added to $A$... so how many times will the loop iterate?  What does this tell you about how large $B$ can get?  What does that say about the running time of your algorithm?

(I am giving only a hint, so you can have the pleasure of working out the answer on your own.)