SOLVE
LATER
Micro's school puts a limit on the maximum number of students that can be enrolled in any course. As the new session is starting all the students have filled their preferences. Now since Micro is very busy, he needs your help. He'll give you details about the courses, their limits and about all the students and their rank in the previous session and about their preferences. Course allotment is done on the basis of student's preference, their respective rank and the limit of the course. Check sample for more clarity. Now help Micro generate the list of course allotment. For better understanding of the problem, refer to the sample explanation given below.
These are three tables that you have to use. The schema of the tables is as given below.
Table : Students
Field | Type |
---|---|
Student_ID | int |
Rank | int |
Table: Courses
Field | Type |
---|---|
Course_ID | int |
CName | text |
CLimit | int |
Table: Preferences
Field | Type |
---|---|
Student_ID | int |
Course_ID | int |
Student_ID |
---|
1 |
2 |
Sample Students table:
Student_ID | Rank |
---|---|
1 | 3 |
2 | 1 |
3 | 4 |
4 | 2 |
Sample Courses table:
Course_ID | CName | CLimit |
---|---|---|
101 | Science | 2 |
102 | Math | 3 |
Sample Preferences table:
Student_ID | Course_ID |
---|---|
1 | 101 |
2 | 101 |
3 | 101 |
1 | 102 |
4 | 101 |
Output:
Student_ID | Course_ID |
---|---|
1 | 102 |
2 | 101 |
4 | 101 |
4 students added \(Science\) as preference but it's limit is 2, so the first 2 students (according to rank), will get the course.
Only 1 student preferred \(Math\), and it's limit is 3, so he'll get it.