Each student sort the departments according to there choice:
Then students gets distributed according to there GPA in each department
If a student is good in all departments, he gets nominated to the 1st choice.
If a student has a high GPA in the courses of Department X and low GPA in the courses of Department Y.
And his Choices were the following:
1st Choice: Department Y
2nd Choice Department X
That student will be nominated to Department X, as he didn't get a high enough GPA to get to Y.
N.B: Once nominated for a specific department, student can't change this department.