Python [set of sums]
The idea is to keep a set of sums for all possible combinations of toppings. As the number of distinct toppings is bounded, so is the set of distinct values the
The idea is to keep a set of sums for all possible combinations of toppings. As the number of distinct toppings is bounded, so is the set of distinct values they can sum to.\n\n```python\nimport copy\nclass Solution:\n    def closestCost(self, base, top, t):\n        top_combo = {0}\n        for x in top:\n            top_combo_next = copy.deepcopy(top_combo)\n            for y in top_combo:\n                top_combo_next.add(y+x)\n                top_combo_next.add(y+2*x)\n            top_combo = top_combo_next\n        \n        ans = dif = math.inf\n        for x in base:\n            for y in top_combo:\n                cost = x+y\n                cdif = abs(t-cost)\n                if cdif < dif:\n                    ans, dif = cost, cdif\n                elif cdif == dif and cost < ans:\n                    ans, dif = cost, cdif\n        \n        return ans\n```
[]