Say I have N cup of waters, each cup with different volume 100ml, 250ml, 355ml, etc. and I have M bottles, each has unlimited volume.
I want to pour all water into the M bottles, and try to balance the water amount poured into different bottles. e.g. I have three cups cup_1
(volume 100ml), cup_2
(volume 100ml), cup_3
(volume 200ml), and I have 2 bottles. The ending result should be:
cup_1 -> bottle_1, cup_2 -> bottle_1, cup_3 -> bottle_2
or
cup_1 -> bottle_2, cup_2 -> bottle_2, cup_3 -> bottle_1
In either case, both bottles will end up with 200ml water, which is the best outcome.
What's the algorithm looks like? The brute force solution is to enumerate all possible combinations, but the time complexity is high. Is there a better way?