You Can Make it Using DP..  (CPP)
\n# Code\n\nclass Solution {\npublic:\n\n    void func(int i,int sum,int &maxi,int &diff,vector<int>&top,int target,vector<vector<int>>&dp){\n\n        if(sum>t
\n# Code\n```\nclass Solution {\npublic:\n\n    void func(int i,int sum,int &maxi,int &diff,vector<int>&top,int target,vector<vector<int>>&dp){\n\n        if(sum>target){\n\n            if(abs(target-sum)<diff){\n                maxi=sum;\n                diff=abs(target-sum);\n            }\n\n            else if(abs(target-sum)==diff){\n                maxi=min(maxi,sum);\n            }\n\n            return ;\n            }\n\n\n        if(abs(target-sum)<diff){\n            maxi=sum;\n            diff=abs(target-sum);\n        }\n\n        else if(abs(target-sum)==diff){\n            maxi=min(maxi,sum);\n        }\n        \n        if(i>=top.size())return;\n\n        if(dp[i][sum]!=-1)return ;\n\n        func(i+1,sum,maxi,diff,top,target,dp);\n        func(i+1,sum+top[i],maxi,diff,top,target,dp);\n        func(i+1,sum+(2*top[i]),maxi,diff,top,target,dp);\n\n        dp[i][sum]=1;\n    }\n\n\n    int closestCost(vector<int>& baseCosts, vector<int>& toppingCosts, int target) {\n        \n        int ans=0,diff=INT_MAX;\n\n        for(int i=0;i<baseCosts.size();i++){\n            int cost=baseCosts[i];\n            int maxi=0,diff1=INT_MAX;\n\n            vector<vector<int>>dp(toppingCosts.size(),vector<int>(target+1,-1));\n\n            func(0,cost,maxi,diff1,toppingCosts,target,dp);\n            \n\n            if(abs(target-maxi)<diff){\n                ans=maxi;\n                diff=abs(target-maxi);\n            }\n            else if(abs(target-maxi)==diff){\n                ans=min(ans,maxi);\n            }\n        }\n        \n        return ans;\n\n    }\n};\n```
['C++']