Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Would it be easier to place the students into valid groups after sorting them based on their grades in ascending order?
Notice that, after sorting, we can separate them into groups of sizes 1, 2, 3, and so on.
If the last group is invalid, we can merge it with the previous group.
This creates the maximum number of groups because we always greedily form the smallest possible group.