C++ | Backtracking solution
```\nclass Solution {\nprivate:\n    void backtrack(int &ans,int curr,int &target,vector&base,vector&top,int index,bool &baseSelected){\n        if(index==top.s
```\nclass Solution {\nprivate:\n    void backtrack(int &ans,int curr,int &target,vector<int>&base,vector<int>&top,int index,bool &baseSelected){\n        if(index==top.size()){\n            if(abs(target-ans)>abs(target-curr)){\n                ans=curr;\n            } else if(abs(target-ans)==abs(curr-target)){\n                ans=min(ans,curr);\n            }\n        } else if(!baseSelected){\n            for(int i=0;i<base.size();i++){\n                baseSelected=true;\n                backtrack(ans,curr+base[i],target,base,top,index,baseSelected);\n                baseSelected=false;\n            }\n        } else {\n            backtrack(ans,curr,target,base,top,index+1,baseSelected);\n            backtrack(ans,curr+top[index],target,base,top,index+1,baseSelected);\n            backtrack(ans,curr+top[index]*2,target,base,top,index+1,baseSelected);\n        }\n    }\npublic:\n    int closestCost(vector<int>& baseCosts, vector<int>& toppingCosts, int target) {\n        int ans=INT_MAX,curr=0;\n        bool baseSelected=false;\n        backtrack(ans,curr,target,baseCosts,toppingCosts,0,baseSelected);\n        return ans;\n    }\n};
['Backtracking', 'C', 'C++']