Answered step by step
Verified Expert Solution
Link Copied!

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 1 with content -1.
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 space-separated integers - avail[0], avail[1],...., avail[M-1], representing the books in the library that have not been issued to any student.
The third line consists of two space-separated 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 space-separated integers representing the books required by the students to complete their assignments.
The next line consists of two space-separated 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 space-separated integers representing the books already issued to the students, respectively.
Output
Print space-separated 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 1 with content -1.
Constraints
1<= booksNum = reqBooks = issuedBooks <=100
1<= studentNum <=100
studentNum = studentIssuedBooks
Example
Input:
3
223
33
240
001
013
33
354
134
235
Output:
201
Explanation
The available Books =[223]
studentID Issued Books Required Books Needs
0240354114
1001134133
2013235222
The needs of the student with the studentID 2 can be met directly as they need only 2,2,2 different books and the available books are 2,2,3. So after the completion of their assignment, the books returned would be 0,1,3. Therefore, the books available in the library would be [223]+[013]=[236].
The students with studentIDs 0 and 1 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 0 would be completed before the student with the studentID 1.
After the completion of the assignment of the student with the studentID 0, the books returned would be 2,4,0. So the books available in the library would be [236]+[240]=[476].
Similarly, for the student with the studentID 1, the books returned would be 0,0,1. So the books available in the library would be [476]+[001]=[477].
Therefore, the optimum order in which the students complete their assignments is [2,0,1].complete this code:
def completionSeq(avail, bookRequire, bookIssued):
return
def main():
# Input for avail
avail =[]
avail_size = int(input())
avail = list(map(int, input().split()))
# Input for bookRequire
bookRequire =[]
bookRequire_rows, bookRequire_cols = map(int, input().split())
for idx in range(bookRequire_rows):
bookRequire.append(list(map(int, input().split())))
# Input for bookIssued
bookIssued =[]
bookIssued_rows, bookIssued_cols = map(int, input().split())
for idx in range(bookIssued_rows):
bookIssued.append(list(map(int, input().split())))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions