Java Recursive
\nclass Solution {\n    int min = Integer.MAX_VALUE;\n    int ans=0;\n    \n    public int closestCost(int[] base, int[] top, int target) {\n        for(int i=0
```\nclass Solution {\n    int min = Integer.MAX_VALUE;\n    int ans=0;\n    \n    public int closestCost(int[] base, int[] top, int target) {\n        for(int i=0;i<base.length;i++){\n            dfs(top,0,target,base[i]);\n        }\n        return ans;\n    }\n    \n    private void dfs(int [] top,int i,int target,int sum){\n        if(i>=top.length){\n            int diff = Math.abs(sum-target);\n            if(diff<min){\n                min = diff;\n                ans = sum;\n            }\n            if(diff==min){\n                ans = Math.min(ans,sum);\n            }\n            return;\n        }\n        \n        dfs(top,i+1,target,sum);\n        dfs(top,i+1,target,sum+top[i]);\n        dfs(top,i+1,target,sum+2*top[i]);\n        \n    }\n}\n```
[]