Python | Backtracking + Memoization
```\n\nclass Solution:\n    def closestCost(self, baseCosts: List[int], toppingCosts: List[int], target: int) -> int:\n        ans = []\n        result = [float
```\n\nclass Solution:\n    def closestCost(self, baseCosts: List[int], toppingCosts: List[int], target: int) -> int:\n        ans = []\n        result = [float(\'inf\')]\n\n        mem = set()\n        def process(b,idx=0):\n            req = (target-b)\n            if abs(req) < abs(target-result[0]) or abs(req)==abs(target-result[0]) and b < target:\n                result[0] = b\n        \n            if b > target:\n                return\n            \n            if (b,idx) in mem:\n                return \n            mem.add((b,idx))\n\n            for i in range(idx,len(toppingCosts)):\n                process(b,i+1)\n                process(b+toppingCosts[i],i+1)\n                process(b+toppingCosts[i]+toppingCosts[i],i+1)\n            \n        \n        for b in baseCosts:\n            process(b)\n        \n        return result[0]\n\t\t
[]