Redistribution Algorithm

185 Views Asked by At

I've one thousand buckets of different sizes. Each bucket consists of red and blue balls of different weights. I know that $60$ percent of the total ball weight comes from the red balls and $40$ percent from the blue balls. Each bucket has a random number of balls, a random distriution of red and blue balls, and random distribution of ball weights.

I need to do a redistribution of the balls so each bucket consists of $59$-$61$ percent ball weight from red balls, and $39$-$41$ percent ball weight from blue balls. Each bucket should have exactly the same weight as it had before the redistribution, but the number of balls in each bucket doesn't have to match the earlier number. It's possible to split balls, but each split has a cost.

Can anyone point me in the direction of an algorithm?

Thanks.