Most intuitive & Easyy Top Down solution || recursion+memoizaton
Idea & thoughts...\n\nwhat will happen after t days if we don\'t delete anything the \ns1: sum of a1\ns2: sum of a2\n\nsum will be = s1 + t*s2\nso now if we wan
Idea & thoughts...\n\nwhat will happen after t days if we don\'t delete anything the \ns1: sum of a1\ns2: sum of a2\n\nsum will be = ```s1 + t*s2```\nso now if we want to delete some index i element at time p then \nsum will be = ```s1+t*s2 - a1[i]- p*a2[i] ```\nSo what we see here is the ```s1+ t*s2 ```remains constant for any t but ```a1[i]+p*a2[i] ```varies and we want to ```sum<=x ``` so we need to minimise the negative part :\nso it will be wise to delete every day some element bcz it will increase negative part, means have to select t elemets out of n\n\nthe maximum no of days can be n if we are not able to do so with in n it\'s not possible \n\nbcz let\'s say u removed some i element at ``` t ``` day ( which had value ``` a1[i]+t*a2[i] ``` at t day ) and after some time ``` p ``` it has become ``` p*a2[i] ``` and now u want to remove it again so it will be again zero but what\'s point of it u can simply delete it after t+p days and have same negative effects but after ``` t+p  ```days it has more addition at other indexes so it doesn\'t helps to decrease sum \n\nas i already satated want to delete something everyday and deleting some index again doesn\'t helps so maximum possible days can be n\n\n\nnow how we select elements ?\ni\'ll be using knap sack approach to maximize negative part by selecting t values from n length array \nbut wait ! we have seen that it doesn\'t matter to a1[i] value when ever we select but a2[i] *t matters \nit\'s more benificial to select ``` a2[i] ``` for greater value of t bcz it will maximize our neg part more \nSo we need to sort values arrording to ``` a2 ``` and priorities high value of ``` a2[i] ``` \n\nin case if u have doubt. for a sec forget about time value\nlet\'s say u selected some t elements out of n \nnow u have to subtract these all elemets from our constant sum ( remember for any t it\'s constant ) to minimise the sum, order doesn\'t matter for ``` a1[i]  ``` bcz anyway they will get subtracted as it is, but for ```a2[i]*t  ```it matters bcz it\'s depends upon order, it\'s wise to delete bigger element late when t is high. \n\nSo this sorting is not for selecting values but for in which order we should subtract those values to maximize negative part, \nin knap sack part all possible ``` t elements ( nCt combiation ) ``` can be selected irrespective of sorting but summation order needs to be in some specific way such that high``` a2[i] ```gets high t value to maximize the solve function that\'s why we need to sort according to ```a2```\n\nImplimentation:\n\nmake a pair of vector : ```{ a2[i],a1[i] }  ```\nthen sort it according to first value( default sorting will work )\n\nthen from t=1 to n check is it possible to get ``` sum<=x ```\nmemoize the whole part , solve function is a knapsack approach to select any t element and return max out of it, one thing to notic is we are using precalculated solutions as well like when we call for ```solve(n-1,i+1)``` we are taking use of already solved solution of```  (n-1, i) ``` by using memoization\n\n**Time : NxN\nSpace : NxN**\n\n\n```\nclass Solution {\npublic:\n    vector<pair<int,int>> a;\n    long long dp[1001][1001];\n    long long solve(int idx, int t)\n    {\n        if(idx<0|| t==0) return 0;\n        if(dp[idx][t]!=-1) return dp[idx][t];\n        long long ans=solve(idx-1,t-1)+a[idx].second+t*a[idx].first;\n        ans=max(ans, solve(idx-1, t));\n        \n        return dp[idx][t]=ans;\n        \n    }\n    int minimumTime(vector<int>& a1, vector<int>& a2, int x) \n    {\n        long long s1=0; for(auto i:a1) s1+=i;\n        long long s2=0; for(auto i: a2) s2+=i;\n        \n        int n=a1.size();\n        for(int i=0; i<n; i++) a.push_back({a2[i],a1[i]});\n        \n        sort(a.begin(),a.end());\n        \n        if(s1<=x) return 0;\n        \n        \n        memset(dp,-1,sizeof(dp));\n        \n        for(int i=1; i<=n; i++)\n        {\n            long long val= solve(n-1,i);\n            if(s1+i*s2-val<=x) return i;\n        }\n        return -1;\n        \n    }\n};\n```
['Recursion', 'Memoization', 'C']