Formula for Calculating original quantities from a price

Hi I need a formula to solve the following problem, unfortunately my maths is pretty basic.

Item A = 0.23 per unit up to and including first 150 units

Item A = 0.18 per unit above 150 units

Item B = 0.15 per unit

Item A Quantity = 400 = (150 * 0.23) + (250 * 0.18) = 79.5

Item B Quantity = 400 * 0.15 = 60.0

----

Total Price = 139.5

----

Now if we have the Total Price, the percentage of the total price which was spent on Item B and the above per unit rates

how do you calculate what quantity of each item was brought originally.

It should be possible to get back to Item A Quantity 400 and Item B Quantity 300 given

Total Price = 139.5

Percentage of Total Price spent on Item B = 50%

Item A = 0.23 per unit up to and including first 150 units

Item A = 0.18 per unit above 150 units

Item B = 0.15 per unit

Thanks in advance for any help

Darren