[C++]  beats 100%, Space complexity: O(N), with explaination
Intuition\n Describe your first thoughts on how to solve this problem. \n\nTo minimize, we have to find out the minimum num to reset to 0.\n\n# Approach\n Descr
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nTo minimize, we have to find out the minimum num to reset to 0.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst, we sort `v` (contains `nums2`, `nums1`).\n\nSecond, we use dynamic programming to calcualte the max sum I could deduct(since we can reset) by resets_times.\n`dp[resets_times] = maximum sum I could set to 0 in resets_times`\n\nThen, we find the answer by loop through all possible seconds from `0` sec.\n\n# Complexity\n- Time complexity: $$O(N^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(N)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp\nclass Solution {\npublic:\n    int minimumTime(vector<int>& nums1, vector<int>& nums2, int x) {\n        int n = nums1.size(); \n        vector<pair<int,int>> v;\n        for (int i = 0; i < n; i++) v.push_back({nums2[i], nums1[i]});\n        sort(v.begin(), v.end());\n        vector<int> dp(n+1, 0);\n        for (int j = 0; j < n; j++)\n            for (int i = n-1; i >= 0; i--) \n                dp[i+1] = max(dp[i+1], dp[i] + v[j].first * (i+1) + v[j].second);\n        int n1 = accumulate(nums1.begin(), nums1.end(), 0);\n        int n2 = accumulate(nums2.begin(), nums2.end(), 0);\n        for (int i = 0; i <= n; i++) \n            if (n2 * i + n1 - dp[i] <= x) \n                return i;\n        return -1;\n    }\n};\n```
['C++']