How do I efficiently partition a set of item pairs with varying quantities

27 Views Asked by At

Apologies in advance if my terminology is off. I'm not a mathematician (just a programmer).

I have a set of item pairs (a shopping cart) where each item has a quantity

1x item A
1x item B
2x item C
1x item D
1x item E

I have a discount code that requires a minimum quantity of items in the cart in order to be applicable. The goal is to maximize the discount.

If the minimum was 3 items, there would be two candidates for this cart:

(A, B, C, D, E) = $50 discount
(A, B, C)  (C, D, E) = $60 discount (since we can use 'C' twice)

Rather than brute-forcing it, is there an algorithm used for calculating the optimal way to partition sets of pairs like these? Or even a hint of a branch of maths I should be looking into?

Thanks in advance for any insight.