Grouping numeric data into efficient group/pool
Sort all devices.

Take the first x elements until their average would be over 5 MB.

Then take the next x2 devices until their average would hit 25 MB.

Straightforward with sorted data. It's not the global optimum but will get you reasonably close.