All Tracks Problem

Micro and Courses
Tag(s):

Muito fácil, Muy fácil, Very-Easy, とてもやさしい, 非常に簡単, 非常简单

Problem
Editorial
Analytics

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.

Input Format

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

Output Format

Student_ID
1
2

Sample Explanation

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
Explanation

$$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.

Time Limit: 1 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: MySQL, PostgreSQL, MSSQL, Oracle_Db

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

Notifications
View All Notifications