Mixed problem headache

I understand the rope anology, but cant wrap my head around why B gets the 16 and A gets the 4, even though on the rope it is inverse. My main question is, do I just always give the “closer value” the bigger ratio or do I always flip the ratio. Thank you!

The average of 40 and 20 is 30, so if you want the average to tend to 24, you’ll need more of the 20 than the 40.