If your interpretation of the problem statement is indeed correct, then the algorithm proposed to you is correct. However, a more effective solution can be proposed.
You can apply an ordinary quick sort algorithm with an additional modification.
If after partitioning it turns out that the sum of the elements in the left (smaller) part of the array is not less than K , then the right part of the array no longer interests you and there is no point in wasting time further sorting the right part.
In the case when the sum of the elements in the left (smaller) part of the array is less than K , you immediately know that all the elements of the left part are obviously part of the desired subarray and there is no point in wasting time further sorting the left part.
This is the same strategy that the classic "k smallest elements" search algorithm works with, with the only difference that you are not looking for k smallest elements, but an unknown number of smallest elements whose sum does not exceed K
Thus, at each level of the recursive subdivision, you need to perform a recursive call for only one half of the subdivision, while the second half is either completely ignored, or just completely sent to the output (and then ignored). Such an algorithm should easily allow a truly cyclic implementation, without using a stack.