#K50392. Maximum Books Returned on Deadline

    ID: 28854 Type: Default 1000ms 256MiB

Maximum Books Returned on Deadline

Maximum Books Returned on Deadline

In this problem, you are given the number of books and their respective return deadlines. Each book must be returned by its deadline, but you cannot return more than one book on the same day. Your task is to determine the maximum number of books that can be returned on time under the constraint that no two books share the same return day.

The strategy is to schedule the returns in a greedy manner. Sort the deadlines in non-decreasing order and then iterate through them. Use the fact that if a book's deadline is strictly greater than the current day you have scheduled, then it can be assigned a new return day. Formally, if the current day is \(d\) and the next book's deadline is \(t\) with \(t > d\), then you can schedule this book on day \(d+1\). Continue this process to achieve the maximum possible count.

Note: If there are no books (i.e. \(n = 0\)), the answer is 0.

inputFormat

The input is read from standard input (stdin). The first line contains an integer (n) representing the number of books. The second line contains (n) space-separated integers representing the deadlines by which each book must be returned. If (n = 0), the second line will be empty.

outputFormat

Output a single integer to standard output (stdout) representing the maximum number of books that can be returned by their respective deadlines with no two books returned on the same day.## sample

4
2 3 2 1
3

</p>