N^2logN solution, DP + Binary search + Maths
Intuition\nYou can see that after a certain day you can get the solution, which gives the intuition of binary search\n\n# Approach\nWe use binary search to get 
# Intuition\nYou can see that after a certain day you can get the solution, which gives the intuition of binary search\n\n# Approach\nWe use binary search to get the answer, the check funtion is a DP function. \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```\nclass Solution {\npublic:\n    int n;\n    int dp[1003][1003];\n    int f(vector<vector<int>> &v, int i, int &time, int t){\n        if(i == n){\n            return 0;\n        }\n        if(dp[i][t] != -1) return dp[i][t];\n        if(t > time) return 0;\n        int ans = max(f(v, i+1, time, t), f(v, i+1, time, t+1) + v[i][1] + t*v[i][0]);\n        return dp[i][t] = ans;\n    }\n    \n    int minimumTime(vector<int>& a, vector<int>& b, int x) {\n        n = a.size();\n        int ans = 0, suma = 0, sumb = 0;\n        vector<vector<int>> v(n);\n        for(int i = 0; i < n; i++){\n            v[i] = {b[i], a[i]};\n            suma += a[i];\n            sumb += b[i];\n        }\n        sort(v.begin(), v.end());\n        int total = 0;\n        for(int i = 0; i < n; i++){\n            int xx = n - i - 1;\n            total += (xx * v[i][0]);\n        }\n        if(suma <= x) return 0;\n        if(total > x) return -1;\n        \n        int lo = 0, hi = n, mid;\n        while(lo <= hi){\n            memset(dp, -1, sizeof(dp));\n            mid = (lo + hi) / 2;\n            int c = f(v, 0, mid, 1);\n            int xx = suma + mid*sumb - c;\n            // dbggg(mid, xx, c);\n            if(xx <= x) hi = mid - 1;\n            else lo = mid + 1;\n        }\n        return hi + 1;\n        \n    }\n};\n```
['C++']