Easy C++ Solution || Memoization|| O(N^2)🔥🔥
Intuition\nBasic intution is that we will iterate a loop over number of operations and at any instant if it satisfies condition of sum of both arrays less than 
# Intuition\nBasic intution is that we will iterate a loop over number of operations and at any instant if it satisfies condition of sum of both arrays less than or equal to x the return operation else return -1 \n\n# Approach\nThe code defines a class named Solution. It uses two arrays named n1 and n2 to hold the numbers from two different sets. There\'s also a 2D array dp used to store intermediate results.\n\nMaxSum Function: There\'s a function named MaxSum which calculates the maximum possible sum considering a certain row and the last index in that row. It does this recursively while memoizing (storing) the results in the dp array to avoid recalculating.\n\nminimumTime Function: This function takes three inputs - two arrays of numbers (nums1 and nums2) and a target sum x. It sorts the numbers in such a way that for each index, the corresponding elements from nums1 and nums2 together form pairs that are sorted based on values in nums2.\n\nMain Logic: The function then iterates through possible numbers of operations (from 0 to the size of the arrays), and calculates the total sum of both sets of numbers considering the current number of operations. It also calculates the maximum possible sum using the MaxSum function for the given number of operations.\n\nCheck and Return: If the difference between the total sum and the maximum possible sum (using MaxSum) is less than or equal to the target x, it means we can achieve the target sum. So, the function returns the current number of operations. It continues this check for different numbers of operations.\n\nConclusion: If no valid number of operations is found within the loop, it means achieving the target sum is not possible. In that case, the function returns -1.\n\n# Complexity\n- Time complexity:\nO(N^2)\n\n- Space complexity:\n\n\n# Code\n```\nclass Solution {\n    int dp[1001][1001];    \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<pair<int,int>> 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].second;\n            n2[j] = n2_n1[j].first;\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++']