Range search in a max-heap
The algorithm you're describing is basically correct.
To summarize in one sentence: &quot;If the current value is less than $x$, turn back.&quot;
The reason it has the desired time complexity is because the set of the nodes you are visiting is precisely:

the root node
all the nodes which are direct descendants of the nodes in the output (since every node has no more than two children, there are no more than $2k$ of these)

So the total number of times the body of your function gets executed is no more than $2k+1$.