C++ Backtracking Solution using Set
\nclass Solution {\npublic:\n    unordered_set<int>s;\n    void dfs(int curr,int ans,int &m, vector<int>&nums2){\n        if(curr==m){\n            s.insert(ans
```\nclass Solution {\npublic:\n    unordered_set<int>s;\n    void dfs(int curr,int ans,int &m, vector<int>&nums2){\n        if(curr==m){\n            s.insert(ans);\n            return;\n        }\n        dfs(curr+1,ans,m,nums2);\n        dfs(curr+1,ans+nums2[curr],m,nums2);\n        dfs(curr+1,ans+(nums2[curr]<<1),m,nums2);\n    }\n    int closestCost(vector<int>& nums1, vector<int>& nums2, int k) {\n        int m=nums2.size(),n=nums1.size(),ans=nums1[0];\n        dfs(0,0,m,nums2);\n        for(int i=0;i<n;i++){\n            for(auto j:s){\n                int sum=nums1[i]+j;\n                if(abs(k-sum)<abs(k-ans) || (abs(k-sum)==abs(k-ans) && sum<ans)){\n                    ans=sum;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['Backtracking', 'Depth-First Search', 'C']