Pseudo Code optimization Summary:

I am struggling with the Pseudo code for an that algorithm assigns "least filled slot first" to a tasks on multi-core chip. 

Detail

So far I have written following: 



What I do not like here is:


In while loop I am removing one by one elements of $R$ (which is a row vector with $m$ elements). This means the complexity of $m^2$, however I could have sorted $R$ outside the loop and then just removed the head every time that would reduce the complexity to $m\log m + m$ for this part. But in that case the index $j$ will get jumbled up and not usable in the rest of the part. Is there an elegant Pseudo-code way of saying "store the indices before sorting for later use"?  
Any other stylistic suggestions that make it easier to read while still reducing the "implementation complexity" ?


In general, I know its a trade-off between readability vs complexity. Generally, the main purpose of presenting an algorithm is to make it readable and leave the implementation details to the implementer. But just to be pedantic ..

Thanks.
I think it would be perfectly reasonable and normal to present the pseudocode as is, and to mention in the accompanying text that if you sort $R$ in advance, you can implement this algorithm in $O(m \log m)$ time.  I think it's pretty clear how to implement the selection step, and you don't need to write out all the indices to explain.