#K13986. Book Borrowing Challenge
Book Borrowing Challenge
Book Borrowing Challenge
In this problem, there are (n) residents who wish to borrow books sequentially. Each resident can hold at most (m) books at any given time. The borrowing process works as follows:
- Residents request books one by one following the order given in the input.
- Each resident maintains a list (queue) of currently held books. When a new book request arrives:
- If the book is already in the resident's current list, the process fails and the answer should be "NO".
- If the resident holds fewer than (m) books, the new book is added to the current list.
- If the resident already holds (m) books, the oldest borrowed book is returned (removed from the list) and the new book is then borrowed (added to the list).
After processing all book requests, if no duplicate borrowing occurs, output "YES"; otherwise, output "NO".
inputFormat
The input is read from standard input (stdin) and contains two lines:
- The first line contains two integers (n) and (m) separated by a space, where (n) is the number of book requests and (m) is the maximum number of books a resident can hold at one time.
- The second line contains (n) space-separated integers, representing the sequence of book IDs requested.
outputFormat
The output is a single line printed to standard output (stdout) containing either "YES" if all book requests are processed without violating the rules, or "NO" if a book is requested that is already held.## sample
5 2
3 2 3 2 1
NO