with a percentage discount, this becomes very tough to accomplish. I assume that the prices of the items in the cart for category B will be different, and you would want the discount to apply to the lowest prices in the cart?
this is going to require some hand coding to accomplish.
you would need to code a loop through the cart to go through each item for category b and return the x lowest prices. Where x is the quantity of category a items.
this hand coding is not supported here in the forums, we could help you with this in a premiere support appointment though.