Binary Search + Dp solution
Approach\nBinary Search + Dp\n\n# Complexity\n- Time complexity: nLogn\n\n# Code\n\nclass Solution {\npublic:\n    int dp[1004][1004];\n    int recur(int i,int 
# Approach\nBinary Search + Dp\n\n# Complexity\n- Time complexity: nLogn\n\n# Code\n```\nclass Solution {\npublic:\n    int dp[1004][1004];\n    int recur(int i,int k, vector<int> &v,vector<pair<int,int>> &p,int op){\n        if(i==v.size() && k==0) return 0;\n        if(i==v.size() && k!=0) return 100000;\n        if(dp[i][k]!=-1) return dp[i][k];\n        int ans = recur(i+1,k,v,p,op) + v[p[i].second] + op*(p[i].first);\n        if(k!=0){\n            ans = min(ans,recur(i+1,k-1,v,p,op) + (k-1)*p[i].first);  \n        }\n        return dp[i][k] = ans;\n    }\n    int minimumTime(vector<int>& nums1, vector<int>& nums2, int target) {\n        vector<pair<int,int>> v;\n        int sum = 0;\n        for(int i=0;i<nums2.size();i++){\n            v.push_back({nums2[i],i});\n            sum+=nums1[i];\n        }\n        if(sum<=target) return 0;\n        sort(v.begin(),v.end());\n        int n = nums1.size();\n        int lo = 1;\n        int hi = n;\n        int mid;\n        while(lo<=hi){\n          mid = (lo+hi)/2;\n            memset(dp,-1,sizeof(dp));\n            if(target>=recur(0,mid,nums1,v,mid))\n                hi = mid -1;\n                else lo = mid +1;\n        }\n        \n        if(hi>=n) return -1;\n        memset(dp,-1,sizeof(dp));\n        if(target>=recur(0,1,nums1,v,1)) return 1;\n        return hi+1;\n\n    }\n};\n```
['Binary Search', 'Dynamic Programming', 'Greedy', 'C++']