Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Items From Sale II

Try to solve the Maximum Number of Items From Sale II problem.

Statement

You are given an integer budget and a 22D integer array items, where items[i] = [factor_i, price_i] represents the factor and price of item i.

You can purchase any number of copies of each item as long as the total cost of all purchased items does not exceed budget.

For each purchased copy of item i, you receive 11 free copy of an item j (where j ≠\neq i) if $ ext{factor}_i$ divides $ ext{factor}_j$. If no such item j exists, you do not receive a free copy for that purchased item.

Return the maximum total number of items, including both purchased and free copies, that you can obtain.

Constraints:

  • 1≤1 \leq items.length ≤105\leq 10^5

  • items[i] =[extfactori,extpricei]= [ ext{factor}_i, ext{price}_i]

  • 1≤extfactori≤1 \leq ext{factor}_i \leq items.length

  • 1≤extpricei≤1091 \leq ext{price}_i \leq 10^9

  • 1≤1 \leq budget ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Items From Sale II

Try to solve the Maximum Number of Items From Sale II problem.

Statement

You are given an integer budget and a 22D integer array items, where items[i] = [factor_i, price_i] represents the factor and price of item i.

You can purchase any number of copies of each item as long as the total cost of all purchased items does not exceed budget.

For each purchased copy of item i, you receive 11 free copy of an item j (where j ≠\neq i) if $ ext{factor}_i$ divides $ ext{factor}_j$. If no such item j exists, you do not receive a free copy for that purchased item.

Return the maximum total number of items, including both purchased and free copies, that you can obtain.

Constraints:

  • 1≤1 \leq items.length ≤105\leq 10^5

  • items[i] =[extfactori,extpricei]= [ ext{factor}_i, ext{price}_i]

  • 1≤extfactori≤1 \leq ext{factor}_i \leq items.length

  • 1≤extpricei≤1091 \leq ext{price}_i \leq 10^9

  • 1≤1 \leq budget ≤109\leq 10^9