C++ DP solution with explanation (~15lines)
Intuition\nAt time $t$, the sum of nums1 without any operations is $sum(nums1)+tsum(nums2)$ which is only dependent on $t$. So the problem turns to maximizing t
# Intuition\nAt time $t$, the sum of nums1 without any operations is $sum(nums1)+t*sum(nums2)$ which is only dependent on $t$. So the problem turns to maximizing the sum of elements we cleared with $t$ operations.\n## Intuition 1\n**Answer should be no larger than $n$.**\nIf the answer is larger than $n$, there must be at least one $i$ that has been cleared at least twice. In this case, the earlier operation is unecessary because it\'s covered by the latter one. \n## Intuition 2\n**index $i$ with smaller $nums2[i]$ should be cleared first.**\nSuppose we perform $t$ operations on index $i_1, i_2,... i_t$. The sum of elements we cleared will be $\\sum_{k=1}^t (nums1[i_k]+nums2[i_k]*k)$. \nFrom [rearrangement inequality](https://en.wikipedia.org/wiki/Rearrangement_inequality), $nums2[i_k]$ for $k =1...t$ should be accending.\nTherefore, to maximize the sum of elements cleared, we need to clear index $i$ with smaller $nums2[i]$ first.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nIt\'s like 0-1 knapsack dp.\ndp[i][j] is the maximum sum of elements cleared with the first $i+1$ elements and $j$ operations.\n$dp[i][j] = max(dp[i-1][j-1] + nums1[i-1] + j * nums2[i-1], dp[i-1][j])$ \nFinally, calculate the sum of elements from $t=0$ to $n$ to see if such $t$ exists.\n\n# Code\n```\nclass Solution {\npublic:\n    int minimumTime(vector<int>& nums1, vector<int>& nums2, int x) {\n        int s1 = accumulate(nums1.begin(), nums1.end(), 0), s2 = accumulate(nums2.begin(), nums2.end(), 0), n = nums1.size();\n        vector<int> dp(n + 1, 0);\n        vector<pair<int, int>> nums;\n\n        for(int i = 0; i < n; i++)\n            nums.push_back({nums2[i], nums1[i]});\n        sort(nums.begin(), nums.end());\n\n        for(int i = 0; i < n; i++)\n            for(int j = i + 1; j > 0; j--)\n                // clear the ith element or not\n                dp[j] = max(dp[j], dp[j-1] + nums[i].second + j * nums[i].first);\n\n        for(int t = 0; t <= n; t++)\n            if(s1 + t * s2 - dp[t] <= x)\n                return t;\n        return -1;\n    }\n};\n```
['C++']