C++ | Backtracking
\nclass Solution {\npublic:\n    int ans = INT_MAX,m;\n    int closestCost(vector<int>& base, vector<int>& topping, int tar) {\n        m = topping.size();\n   
```\nclass Solution {\npublic:\n    int ans = INT_MAX,m;\n    int closestCost(vector<int>& base, vector<int>& topping, int tar) {\n        m = topping.size();\n        for(int i = 0; i < base.size(); i++)\n            helper(base,topping,tar,base[i],0);\n        return ans;\n    }\n    void helper(vector<int>& base, vector<int>& topping, int tar,int sum,int j) {\n        if(abs(sum - tar) < abs(ans-tar)){\n            ans = sum;\n        } \n        else if(abs(sum - tar) == abs(ans - tar)) {\n            ans = min(ans,sum);\n        }\n        if( j >= m || sum >= tar) return;\n        \n        for(int k = 0; k < 3; k++) {\n            sum += (topping[j]*k);\n            helper(base,topping,tar,sum,j+1);\n            sum -= (topping[j]*k);\n        }\n    }\n};\n```
[]