Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A librarian runs a small library that has N number of student patrons. Each student member has a unique studentID. The library has a certain
A librarian runs a small library that has N number of student patrons. Each student member has a unique studentID. The library has a certain number of books on M different subjects. The teacher has given each student an individual assignment for which they will need to consult several different books. Prior to the assignment, the library had already issued some books to the students. The students may still take additional books from the library to complete their respective assignments. After completing their assignments, each student returns the books that they have borrowed. Only when a book has been returned can another student borrow that book. When assigning books, the librarian begins with the student with the smallest studentID and then proceeds with the IDs in increasing order. When they reach the student with the largest studentID, they then go back to the student with the smallest studentID who has not yet borrowed the book. Then the process continues in the same way. The librarian wants to find the sequence of studentIDs that is optimal for the students to complete their assignments.
Write an algorithm to help the librarian find the sequence of studentIDs that is optimal for the students to complete their assignments. If it is not possible for all the students to complete their assignments, output a list of length with content
Input
The first line of the input consists of an integer booksNum, representing the number of different subjects M
The second line consists of M spaceseparated integers avail avail availM representing the books in the library that have not been issued to any student.
The third line consists of two spaceseparated integers studentNum and reqBooks, representing the number of students N and number of different books required by each student It is always equal to the number of different subjects M respectively.
The next N lines consist of M spaceseparated integers representing the books required by the students to complete their assignments.
The next line consists of two spaceseparated integers studentIssuedBooks and issuedBooks, representing the number of students with books issued It is always equal to number of students N and number of different books issued to each student It is always equal to the number of different subjects M respectively.
The next N lines consist of M spaceseparated integers representing the books already issued to the students, respectively.
Output
Print spaceseparated integers representing the sequence of studentIDs that is optimal for the students to complete their assignments. If it is not possible for all students to complete their assignments, output a list of length of with content
Constraints
booksNum reqBooks issuedBooks
studentNum
studentNum studentIssuedBooks
Example
Input:
Output:
Explanation
The available Books
studentID Issued Books Required Books Needs
The needs of the student with the studentID can be met directly as they need only different books and the available books are So after the completion of their assignment, the books returned would be Therefore, the books available in the library would be
The students with studentIDs and can complete their assignments with the books available in the library. However, since preference is given to the student with a smaller studentID, the assignment of the student with the studentID would be completed before the student with the studentID
After the completion of the assignment of the student with the studentID the books returned would be So the books available in the library would be
Similarly, for the student with the studentID the books returned would be So the books available in the library would be
Therefore, the optimum order in which the students complete their assignments is complete this code:
def completionSeqavail bookRequire, bookIssued:
return
def main:
# Input for avail
avail
availsize intinput
avail listmapint inputsplit
# Input for bookRequire
bookRequire
bookRequirerows, bookRequirecols mapint inputsplit
for idx in rangebookRequirerows:
bookRequire.appendlistmapint inputsplit
# Input for bookIssued
bookIssued
bookIssuedrows, bookIssuedcols mapint inputsplit
for idx in rangebookIssuedrows:
bookIssued.appendlistmapint inputsplit
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started