You are given a 2D integer array items, where items[i] = [factori, pricei] represents the ith item. You are also given an integer budget.
There are unlimited copies of each item available for purchase.You may buy any number of copies of any items such that the total cost of the purchased copies is at most budget.
After buying items, you may receive free copies according to the following rules:
i that you bought at least one copy of, you receive one free copy of every item j such that j != i and factori divides factorj.i does not give additional free copies through item i.j can be received multiple times for free if it is received from purchases of different item types.Return the maximum total number of item copies you can obtain, including both purchased copies and free copies, while spending at most budget on purchased items.
Example 1:
Input: items = [[6,2],[2,6],[3,4]], budget = 9
Output: 4
Explanation:
2 * 2 + 4 = 8, which is not greater than budget = 9.factor2 = 3 divides factor0 = 6.Example 2:
Input: items = [[2,4],[3,2],[4,1],[6,4],[12,4]], budget = 8
Output: 10
Explanation:
4 + 2 + 2 * 1 = 8.Constraints:
1 <= items.length <= 1000items[i] = [factori, pricei]1 <= factori, pricei <= 15001 <= budget <= 1500Loading editor...
[[6,2],[2,6],[3,4]] 9