Step by Step solution  with comments | Beats 100%
Intuition\n- After choosing a base , backtrack for adding topplings and select the optimal answer.\n# Approach\n\n\n# Complexity\n- Time complexity : O(n*3^m)\n
# Intuition\n- After choosing a base , backtrack for adding topplings and select the optimal answer.\n# Approach\n\n\n# Complexity\n- Time complexity : O(n*3^m)\n\n- Space complexity : Stack space=O(m)\n\n# Code\n```\nclass Solution {\npublic:\nint ans=1e9, target;\n    void solve(int curr, int idx, int freq, vector<int>& tc)\n    {\n        // more the closer to target, better the answer.\n        if(abs(curr-target)<abs(ans-target)) ans=curr;\n        // if closeness is same, answer will be the smaller one.\n        else if(abs(curr-target)==abs(ans-target) && curr<ans) ans=curr;\n        // return when idx is out of array of curr_cost is greater the target.\n        if(curr>=target || idx==tc.size()) return;\n        // take : can use any toppling atmost 2 times\n        if(freq<2) solve(curr+tc[idx], idx, freq+1, tc);\n        // notTake \n        solve(curr,idx+1,0,tc);\n    }\n    int closestCost(vector<int>& baseCosts, vector<int>& tc, int t) {\n        int n=tc.size();\n        target=t;\n        for(auto x:baseCosts) solve(x,0,0,tc);\n        return ans;\n    }\n};\n```
['Backtracking', 'C++']