basically i need some algorithm that fits into the following problem:
i have 5 lists: 10, 30, 40, 40 and 50 elements each
there is a cap of 80 elements
what i want to achieve now, is this:
3 lists: 10, 80 and 80 elements
40 and 40 merge to 80 and 30 and 50 merge to 80, the list with 10 elements is left as the third resulting list
meaning i want to somehow merge all lists, but with a cap of 80 elements, so i really only have as many lists as i really need
this is not a question of sorting but only to merge
it is not possible to split lists up, the elements of a list should always keep together
hope you can help me, thanks!
This sounds like a bin packing problem .. it’s an NP-hard problem, so you can’t achieve this quickly without some heuristic. The wikipedia page has some code that may be able to help you — now that you have a name for it maybe you can search more.