Solution
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\n    public int minimumTime(List<Integer> nums1, List<Integer> nums2, int x) {\n        \n        final int[][] pairs = new int[nums1.size()][2];\n        int sum1 = 0;\n        int sum2 = 0;\n        for (int i = 0; i < nums1.size(); ++i) {\n            final int n1 = nums1.get(i);\n            final int n2 = nums2.get(i);\n            sum1 += n1;\n            sum2 += n2;\n            pairs[i][0] = n1;\n            pairs[i][1] = n2;\n        }\n       \n        Arrays.sort(pairs, (a, b) -> {\n            int diff = Integer.compare(a[1], b[1]);\n            if (diff == 0) {\n                diff = Integer.compare(a[0], b[0]);\n            }\n            return diff;\n        });\n        final int n = pairs.length;\n        \n        final int[][] dp = new int[n + 1][n + 1];\n        for (int i = 1; i <= n; ++i) {\n            for (int j = 1; j <= i; ++j) {\n                final int withoutIthPair = dp[i - 1][j];  \n                final int withIthPair = dp[i - 1][j - 1] \n                        + (pairs[i - 1][1] * j)  \n                        + pairs[i - 1][0];       \n                dp[i][j] = Math.max(withoutIthPair, withIthPair);\n            }\n        }\n        \n        for (int t = 0; t <= n; ++t) {\n            final int sum = sum1 + (sum2 * t) - dp[n][t];\n            if (sum <= x) {\n                return t;\n            }\n        }\n         \n        return -1;\n    }\n\n}\n```
['Java']