Video Explanation ("All" the proofs - Exchange Arguments)
Explanation \n\nClick here for the video link\n\n# Code\n\n#define pii pair<int, int>\n#define F first\n#define S second\n\nint dp[1001][1001];\n\nclass Solutio
# Explanation \n\n[Click here for the video link](https://youtu.be/7KaJamPY7yA)\n\n# Code\n```\n#define pii pair<int, int>\n#define F first\n#define S second\n\nint dp[1001][1001];\n\nclass Solution {\n    \n    vector<int> n1, n2;\n    \n    int MaxSum(int row, int last_ind) {\n        if (row == 0 || last_ind < 0) return 0;\n        \n        int& ans = dp[row][last_ind];\n        if (ans != -1) return ans;\n        \n        ans = max (\n            MaxSum (row, last_ind - 1),\n            (n1[last_ind] + n2[last_ind]*row) + MaxSum (row-1, last_ind-1)\n        );\n        return ans;\n    }\n    \npublic:\n    int minimumTime(vector<int>& nums1, vector<int>& nums2, int x) {\n        int n = nums1.size();\n        \n        n1.clear(), n2.clear();\n        n1.resize(n), n2.resize(n);\n        \n        vector<pii> n2_n1; \n        for (int j = 0; j < n; j ++) n2_n1.push_back({nums2[j], nums1[j]});\n        sort (n2_n1.begin(), n2_n1.end());\n        \n        for (int j = 0; j < n; j ++) {\n            n1[j] = n2_n1[j].S;\n            n2[j] = n2_n1[j].F;\n        }\n        \n        memset(dp, -1, sizeof(dp));\n        \n        for (int op = 0; op <= n; op ++) {\n            int sum = 0;\n            for (int j = 0; j < n; j ++) sum += n1[j] + n2[j]*op;\n            \n            if ((sum - MaxSum(op, n-1)) <= x) return op;\n        }\n        \n        return -1;\n    }\n};\n```
['C++']