class Solution: def minimumRemoval(self, beans: List[int]) -> int: beans.sort() n = len(beans) ans = [0] * n ans[0] = sum(beans) - n * beans[0] for i in range(1, n): ans[i] = ans[i - 1] + beans[i - 1] - (beans[i] - beans[i - 1]) * (n - i) return min(ans)