Since you have ranges, I would first go by range. As a feature recommendation system I'm guessing that things in lower slots are more important. I would arrange the ranges with items that belong there sorted by lowest slot, then highest slot. I assume the items you don't list can go anywhere, so you would have these ranges:
* Range A - Low: 1, High: 1, Items: 5
* Range B - Low: 1, High: 9, Items: 6, 7, 8, 9
* Range C - Low: 3, High: 5, Items: 1, 2
* Range D - Low: 7, High: 9, Items: 3, 4
Then start picking items from the first range. When you pick an item, it could do away with an entire range, or adjust the starting number of a range and cause a re-order if inside that range. Here's the steps I see:
1. Need an item for slot 1, pick the first range in our list (A) and take item 5. That's the last item, so remove range A. The next range low we need to worry about is 3, so no re-arranging:
2. Range B - Low: 1, High: 9, Items: 6, 7, 8, 9
3. Range C - Low: 3, High: 5, Items: 1, 2
4. 946
Range D - Low: 7, High: 9, Items: 3, 4
5. For slot 2 we need to pick an item, the only range available is Range B, so take 6 and remove it from Range B
6. Range B - Low: 1, High: 9, Items: 7, 8, 9
7. Range C - Low: 3, High: 5, Items: 1, 2
8. Range D - Low: 7, High: 9, Items: 3, 4
9. For slot 3 we have a new range available, Range C. Since range C has a lower maximum slot than range B, we re-arrange to put range C first:
10. Range C - Low: 3, High: 5, Items: 1, 2
11. Range B - Low: 3, High: 9, Items: 7, 8, 9
12. Range D - Low: 7, High: 9, Items: 3, 4
And we take Item 1 from range C for slot 3 and remove it:
* Range C - Low: 3, High: 5, Items: 2
* Range B - Low: 3, High: 9, Items: 7, 8, 9
* Range D - Low: 7, High: 9, Items: 3, 4
* for slot 4 we have no new ranges available, so keep taking from range C, which will take item 2 and remove range C:
* Range B - Low: 3, High: 9, Items: 7, 8, 9
* Range D - Low: 7, High: 9, Items: 3, 4
* The We can't add from range D until we get to slot 7, so keep taking items from range B and take and remove items 7 and 8 for slots 5 and 6:
* Range B - Low: 3, High: 9, Items: 9
* Range D - Low: 7, High: 9, Items: 3, 4
* Now at slot 7 we have a new range available, Range D. However since it's maximum slot is the same as range B, there's no need to re-order. We can finish off taking item 9 and removing range B, then taking items 3 and 4 from range D.
If the High of range B had been 10 and it had another item, we would have re-arranged putting D first because it had a lower maximum slot. 143