Well, I did not know how to solve it in an hour...
Trying to backtrack, but do not know how.... Leetcode, you win, ok?\n\nFor your reference, something like this:\n\n\nprivate:\n\tint ans = -1;\npublic:\n    voi
Trying to backtrack, but do not know how.... Leetcode, you win, ok?\n\nFor your reference, something like this:\n\n```\nprivate:\n\tint ans = -1;\npublic:\n    void dfs(int cost, const vector<int>& b, int pos, int target) {\n        if (pos == b.size()) {\n            if (ans == -1 || abs(cost - target) < abs(ans - target) || (abs(cost - target) == abs(ans - target) && cost < ans)) {\n                ans = cost;\n            }\n            return;\n        }\n        dfs(cost, b, pos + 1, target);\n        dfs(cost + b[pos], b, pos + 1, target);\n        dfs(cost + b[pos] * 2, b, pos + 1, target);\n    }\n    \n    int closestCost(vector<int>& baseCosts, vector<int>& toppingCosts, int target) {\n        int m = baseCosts.size();\n        int n = toppingCosts.size();\n        for (int i = 0; i < m; ++i) {\n            dfs(baseCosts[i], toppingCosts, 0, target);\n        }\n        return ans;\n    }\n```\n\n
[]