Optimization problem: splitting elements that are preferred to be together

Any high level language applicable.

I have a list of lists, let’s say 10 values in total. List size is: 10 >= size >= 1
Each list represents the values that are preferred to keep together if possible. I need to split them between a specific number of chunks (numberOfChunks), so that the size of each chunk is close to the preferred size (preferredChunkSize = total elements / numberOfChunks) and the real chunk size should follow the condition: preferredChunkSize + maxDeviation >= real chunk size >= preferredChunkSize - maxDeviation.

Function declaration:

function split(buckets: list<list>, numberOfChunks, maxDeviation)

Example 0

buckets = [[1, 2, 3], [4], [5], [6, 7, 8, 9, 10]]
chunks = split(buckets, 5, 0)
// acceptable options (max deviation equals 0, so we don't allow the size to be more or less than 2
// [[1,2],[3,4],[5,6],[7,8],[9,10]]

Example 1

buckets = [[1, 2, 3], [4], [5], [6, 7, 8, 9, 10]]
chunks = split(buckets, 5, 1)
// acceptable options
// [[1,2,3],[4],[5],[6,7,8],[9,10]]

Example 2

buckets = [[1,2,3,4,5,6], [7,8], [9], [10]]
chunks = split(buckets, 2, 1)
// acceptable options
// [[1,2,3,4,5,6],[7,8,9,10]]

Example 3

buckets = [[1,2,3,4,5,6], [7,8], [9], [10]]
chunks = split(buckets, 3, 1)
// acceptable options
// [[1,2,3], [4,5,6], [7,8,9,10]]

Any help will be appreciated! Maybe this or a similar problem already exists? Can anyone name it?