[C++] simple dp
\nusing ll = long long;\n\nconst int N = 1010, INF = 1e9;\nll dp[N][N];\n\nvoid init(int n) {\n    for(int i = 0; i <= n; i++) {\n        for(int j = 0; j <= n;
```\nusing ll = long long;\n\nconst int N = 1010, INF = 1e9;\nll dp[N][N];\n\nvoid init(int n) {\n    for(int i = 0; i <= n; i++) {\n        for(int j = 0; j <= n; j++) {\n            dp[i][j] = -INF;\n        }\n    }\n}\n\nclass Solution {\npublic:\n    int minimumTime(vector<int>& a, vector<int>& b, int x) {\n        int n = a.size();\n        init(n);\n        long long s1 = 0, s2 = 0;\n        for(int x : a) s1 += x;\n        for(int x : b) s2 += x;\n        \n        if(s1 <= x) return 0; \n        \n        vector<ll> p(n + 1);\n        for(int i = 1; i <= n; i++) {\n            p[i] = s1 + s2 * i;\n        }\n        \n        vector<pair<int, int>> c;\n        for(int i = 0; i < n; i++) c.push_back({b[i], a[i]});\n        sort(c.begin(), c.end());\n        \n        //base not change\n        //select x integers\n        dp[0][0] = 0;\n        for(int i = 1; i <= n; i++) {\n            int x = c[i - 1].second, y = c[i - 1].first;\n            for(int j = 0; j <= i; j++) {\n                dp[i][j] = dp[i - 1][j];\n                if(j) {\n                    dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + x + (j + 0ll) * y);\n                }\n            }\n        }\n        \n        for(int j = 1; j <= n; j++) {\n            for(int i = 1; i <= n; i++) {\n                if(dp[i][j] + x >= p[j]) {\n                    return j;\n                }\n            }\n        }\n        \n        return -1;\n    }\n};\n```
[]