Variable profit knapsack sorry for bad formatting earlier

We are given Cx,i, Cy,i, Cz,i ∈ ℕ and Px,i, Py,i, Pz,i > 0 for i=1,2,3 such that Px,1 &lt; Px,2 &lt; Px,3, Py,1 &lt; Py,2 &lt; Py,3, and Pz,1 &lt; Pz,2 &lt; Pz,3. We are also given K∈ℕ.

The values Cx,i and Px,i describe the content of a stack named x. From top to bottom, the stack x contains Cx,1 items each of profit Px,1, Cx,2 items each of profit Px,2, and Cx,3 items each of profit Px,3. The contents of stacks y and z are defined in the same way.

We are allowed to pop K items in total from the three stacks. How can I maximize the total profit?
This is not an answer, but the description of a problem which I think the asker wants to ask.

To vaibhav: While I believe that this is at least close to what you want to ask, please edit the question so that it is clearly understandable.  Otherwise, we can only make a guess about what is being asked.

We are given Cx,i, Cy,i, Cz,i ∈ ℕ and Px,i, Py,i, Pz,i &gt; 0 for i=1,2,3 such that Px,1 &lt; Px,2 &lt; Px,3, Py,1 &lt; Py,2 &lt; Py,3, and Pz,1 &lt; Pz,2 &lt; Pz,3.  We are also given K∈ℕ.

The values Cx,i and Px,i describe the content of a stack named x.  From top to bottom, the stack x contains Cx,1 items each of profit Px,1, Cx,2 items each of profit Px,2, and Cx,3 items each of profit Px,3.  The contents of stacks y and z are defined in the same way.

We are allowed to retrieve K items in total from the three stacks.  How can we find efficiently the way to maximize the total profit?