This looks like you'd be better with a second list for B, the first list has items A and C. The mappings would be much easier to achieve. Is this possible or is there a reason to include B in the list?
Try this! Let's use only one list to achieve this.
Step 1: Create a mapping table module as below and make it as manual input,
Step 2: In the allocation module create 2 more line items and apply the below rules,
Then this is how the end result would look like,
Assumptions: 1. The list has Top Level Item, 2. With the help of the mapping table, the total cost will be allocated to the marked entries, here in this case B1 and B2 which takes the cost of all A and C entries.