Passes All test cases But Still showing TLE..
My Code:\nclass Solution {\npublic:\n    \n    int closestCost(vector& bc, vector& tc, int t) {\n        \n        \n        \n        int n=tc.size();\n       
My Code:\nclass Solution {\npublic:\n    \n    int closestCost(vector<int>& bc, vector<int>& tc, int t) {\n        \n        \n        \n        int n=tc.size();\n        \n        for(int i=0;i<n;i++){\n            tc.push_back(tc[i]);\n        }\n        tc.push_back(0);\n      \n        int ans=INT_MAX;\n        \n        \n        for(int i=0;i<bc.size();i++){\n            if(abs(bc[i]-t)<abs(ans-t))ans=bc[i];\n        }\n        for(int k=0;k<bc.size();k++)\n        {\n            vector<vector<int>> dp(tc.size()+1,vector<int>(15000,0));\n            \n            for(int i=1;i<tc.size()+1;i++)\n            {\n                for(int j=0;j<15000;j++)\n                {\n                    \n                    dp[i][j]=dp[i-1][j];\n                    if(j-tc[i-1]>=0){\n                        dp[i][j]=max(dp[i][j],tc[i-1]+dp[i-1][j-tc[i-1]]);\n                    }\n                    \n                    if(abs(dp[i][j]+bc[k]-t)<abs(ans-t)){\n                        ans=dp[i][j]+bc[k];\n                    }else if(abs(dp[i][j]+bc[k]-t)==abs(ans-t)){\n                        if(dp[i][j]+bc[k]<ans){\n                            ans=dp[i][j]+bc[k];\n                        }\n                    }\n                }\n            }\n        }\n        return ans;\n        \n    }\n};
[]