Easy Iterative Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\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\n        int sum = 0, sum2 = 0; \n        for(auto it: nums1) sum += it;\n        for(auto it: nums2) sum2 += it;\n        if(sum <= x) return 0;\n        if(n == 1) return 1;\n\n        vector<pair<int, int> > v;\n        for(int i = 0; i < n; i++){\n            v.push_back({nums2[i], nums1[i]});\n        }\n        sort(v.begin(), v.end());\n\n        vector<vector<long long> > dp(n+1, vector<long long> (n+1, -1e6));\n        for(int i = 0; i <= n; i++){\n            dp[i][0] = 0;\n        }\n        for(int i = 0; i <= n; i++) dp[0][i] = 0;\n        for(long long i = 1; i <= n; i++){\n            for(long long j = 1; j <= n; j++){\n                dp[i][j] = max(dp[i-1][j], v[i-1].second + j * v[i-1].first + dp[i-1][j-1]);\n            }\n        }\n\n        for(int i = 0; i <= n; i++){\n            if(sum + sum2 * i - dp[n][i] <= x) return i;\n        }\n\n        return -1;\n    }\n};\n```
['Array', 'Dynamic Programming', 'Sorting', 'C++']