#K70832. Library Book Borrowing Eligibility
Library Book Borrowing Eligibility
Library Book Borrowing Eligibility
You are given information about a library's book inventory and a user's currently borrowed books. The library contains N distinct books, each with a given number of available copies. A user has currently borrowed M books (each represented by their index in the inventory). The user wishes to borrow a book with index K.
The decision is made by checking the following constraints:
- If the user has already borrowed at least 3 different books, i.e. if \(M \geq 3\), then the user cannot borrow any more books.
- If the user has already borrowed the book with index K, then they cannot borrow it again.
- If there are no available copies of the book K (i.e. the available copies \(\le 0\)), then the borrowing is denied.
If none of the above conditions prevent borrowing, then the book can be borrowed. Output "Yes" if the book is available to borrow, otherwise output "No".
inputFormat
The input is provided via standard input (stdin) in the following order:
- An integer N representing the total number of distinct books.
- N space-separated integers representing the number of copies available for each book. The i-th integer corresponds to the number of copies of the book with index i.
- An integer M representing the total number of books the user has already borrowed.
- M space-separated integers representing the indices of the books that the user has currently borrowed.
- An integer K representing the index of the book the user wants to borrow.
Note: It is guaranteed that the book indices for available copies and borrowed books are in the range [0, N-1].
outputFormat
The output (written to stdout) is a single line: "Yes" if the user can borrow the book, or "No" if the borrowing is not allowed based on the constraints.## sample
5
3 1 0 2 4
2
1 3
4
Yes