# Algorithms – Place elements in compatible bucket types to find optimal total value

Suppose we have a list of compartments, each with a unique type and maximum capacity. We also have a list of items, each with a value and a list of compatible bucket types. An article is compatible with a type of bucket if and only if it can be inserted into a bucket of this type. The goal is to insert the elements into the compartments so that the total value of the elements inserted is the highest.

For example:

``````Articles:
compatible with | value
A, B, C | 17641
A, B, C | 14821
A, B | 14274
A, B | 13.755
A, B | 12.240
A, B | 12.240
B, C | 11960
A, B | 10,270
A, B, C | 9958
A, B, C | 8552

buckets:
type of bucket | capacity
One | 2
B | 3
C | 4

Solution:
bucket | values
One | 17.641, 12.240
B | 14.274, 13.755, 12.240
C | 11.960, 9.958, 8.552, 14.821
``````

Is this problem a special case of existing problems? I find it difficult to think of an algorithm to solve it, but I think a good solution would require going through the list of items several times and keeping a queue with the best results for each type of bucket.

What would be the maximum complexity of the resulting algorithm? Can a situation with 5 types of compartments and 30 elements explode in calculation costs?