Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Notice that if we choose to make x bags of beans empty, we should choose the x bags with the least amount of beans.
Notice that if the minimum number of beans in a non-empty bag is m, then the best way to make all bags have an equal amount of beans is to reduce all the bags to have m beans.
Can we iterate over how many bags we should remove and choose the one that minimizes the total amount of beans to remove?
Sort the bags of beans first.