This is a DIFFERENT PROBLEM than the one you originally describe.
Let me try asking you a question, so I can try and understand your logic. Why did you separate out the fourthYear in your final destination? Can the final chunks only have at most 2 people in them?
You must assign all students to groups.
There can be many groups.
Every group may have at most 2 people in it.
Every first year must be paired with a non-firstyear.
For clarification:
imagine 3 rooms, where 2 of them need 2 student inside at morning and 2 two at evening.
Remaining one need only 1 in the morning. ← answer
I understand now this very interesting question. Actually no. There can be even more studenyi depending on the number of students assigned at the beginning. However, the last one in the figure houses only one as it is less important than the first two. Therefore, the first two most important classes cannot have two first year students for reasons of experience…
Based on the new information, I would separate out the first years, then pair them up with non-first years. It’s a simple solution that seems to meet all of the criteria.