C++ solution
\nclass Solution {\npublic:\n    int closestCost(vector<int>& baseCosts, vector<int>& toppingCosts, int target) {\n        int n = baseCosts.size();\n        in
```\nclass Solution {\npublic:\n    int closestCost(vector<int>& baseCosts, vector<int>& toppingCosts, int target) {\n        int n = baseCosts.size();\n        int m = toppingCosts.size();\n        int minDiff = INT_MAX;\n        vector<int> ans;\n        for (int i=0; i<n; i++) {\n            queue<int> q;\n            int val = baseCosts[i], level=0;\n            q.push(val);\n            while (!q.empty()) {\n                queue<int> newq;\n                while (!q.empty()) {\n                    int curr = q.front();\n                    //cout << curr << ", ";\n                    q.pop();\n                    int curDiff = abs(curr-target);\n                    if (curDiff == minDiff) {\n                        ans.push_back(curr);\n                    } else if (curDiff < minDiff) {\n                        minDiff = curDiff;\n                        ans.clear();\n                        ans.push_back(curr);\n                    }\n                    if (level>=m)\n                        continue;\n                    newq.push(curr);\n                    newq.push(curr+toppingCosts[level]);\n                    newq.push(curr+toppingCosts[level]*2);\n                }\n                q = newq;\n                //cout << endl;\n                level++;\n                if (level>=m+1)\n                    break;\n            }\n        }\n        sort(ans.begin(), ans.end());\n        return ans[0];\n    }\n};\n```
[]