Java
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```\nclass Solution {\n        public int minimumTime(List<Integer> A, List<Integer> B, int x) {\n        int n = A.size(), sa = 0, sb = 0, dp[] = new int[n + 1];\n        List<List<Integer>> BA = new ArrayList<>();\n        for (int i = 0; i < n; i++) {\n            int a = A.get(i), b = B.get(i);\n            BA.add(Arrays.asList(b, a));\n            sa += a;\n            sb += b;\n        }\n        Collections.sort(BA, (o1, o2) -> Integer.compare(o1.get(0), o2.get(0)));\n        for (int j = 0; j < n; ++j)\n            for (int i = j + 1; i > 0; --i)\n                dp[i] = Math.max(dp[i], dp[i - 1] + i * BA.get(j).get(0) + BA.get(j).get(1));\n        for (int i = 0; i <= n; ++i)\n            if (sb * i + sa - dp[i] <= x)\n                return i;\n        return -1;\n    }\n}\n```
['Java']