When does this algorithm fail?
Here is a counterexample, with $p = 2$:


stack 1: $600,600$.
stack 2: $1000,0$.
stack 3: $1000,0$.


Your algorithm will choose the top element from stack 1 and one of the top elements from the other stacks, but it is better to choose the top elements of stack 2 and stack 3.

Disclaimer: This is based on your description of the algorithm. I don't understand some of the notation in the algorithm itself.