Get the correct DP state before thinking of solution !
Intuition\nYou need to think of correct dp state in this question.\nIf we calculate to what extent you can reduce the sum of nums1 in each operation we can get 
# Intuition\nYou need to think of correct dp state in this question.\nIf we calculate to what extent you can reduce the sum of nums1 in each operation we can get the answer.\n\n# Approach\n* Let dp[i][j] represent the maximum total value that can be reduced if we do j operations on the first i elements\n* It can also be proven that if we select several indexes i1, i2, ..., ik and set nums1[i1], nums1[i2], ..., nums1[ik] to 0, it\u2019s always optimal to set them in the order of nums2[i1] <= nums2[i2] <= ... <= nums2[ik] (the larger the increase is, the later we should set it to 0).\n* Let\u2019s sort all the values by nums2 (in non-decreasing order). Let dp[i][j] represent the maximum total value that can be reduced if we do j operations on the first i elements. Then we have dp[i][0] = 0 (for all i = 0, 1, ..., n) and dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1] + nums2[i - 1] * j + nums1[i - 1]) (for 1 <= i <= n and 1 <= j <= i).\n* The answer is the minimum value of t, such that 0 <= t <= n and sum(nums1) + sum(nums2) * t - dp[n][t] <= x, or -1 if it doesn\u2019t exist.\n\n\n\n# Complexity\n- Time complexity:\nO(N^2)\n\n- Space complexity:\nO(N^2)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minimumTime(vector<int>& nums1, vector<int>& nums2, int x) {\n        int n = nums1.size();\n       vector<vector<int>> dp(n+1,vector<int> (n+1));\n       vector<pair<int,int>> numssort(n);\n       for(int i=0;i<n;i++) numssort[i] = {nums2[i],i};\n       sort(numssort.begin(),numssort.end());\n       for(int i=1; i<=n;i++){\n           for(int j=1;j<=i;j++){\n               int x = numssort[i-1].first;\n               int y = nums1[numssort[i-1].second];\n               dp[i][j] = max(dp[i-1][j],dp[i-1][j-1] + x*j + y);\n           }\n       } \n       int ans = n+1;\n       int sum1 = 0 ,sum2 = 0;\n       sum1 = accumulate(nums1.begin(),nums1.end(),sum1);\n       sum2 = accumulate(nums2.begin(),nums2.end(),sum2);\n       for(int t=0;t<=n;t++){\n           if(sum1 + sum2*t - dp[n][t] <= x){\n               ans = t;\n               break;\n           }\n       }\n       return (ans==n+1)?-1:ans;\n    }\n};\n```
['Dynamic Programming', 'Sorting', 'C++']