#C4745. Maximum Books on Shelf

    ID: 48317 Type: Default 1000ms 256MiB

Maximum Books on Shelf

Maximum Books on Shelf

Sarah has a collection of n books, each with a given width. She also has a shelf that can accommodate books having a maximum width of w. However, she has a peculiar constraint: no two books with the same width can be placed consecutively on the shelf. Moreover, a book can only be placed on the shelf if its width does not exceed w (i.e. \( x \leq w \) for a book of width \( x \)).

Your task is to determine the maximum number of books that Sarah can place on the shelf. Note that since the order of the books can be rearranged arbitrarily, the constraint on adjacent books essentially implies that only one book of each acceptable width can be used.

Example:

Input: n = 5, w = 10, book_widths = [1, 2, 3, 4, 5]
Output: 5

In this example, all books satisfy the width requirement and have distinct widths, allowing Sarah to place 5 books on the shelf.

inputFormat

The input is read from standard input and contains two lines:

  • The first line contains two integers n and w separated by a space, where \( n \) is the number of books and \( w \) is the maximum width that the shelf can accommodate.
  • The second line contains \( n \) integers representing the widths of the books.

You may assume that the input values are valid and satisfy the constraints of the problem.

outputFormat

The output is a single integer printed to standard output representing the maximum number of books that can be placed on the shelf under the given conditions.

## sample
5 10
1 2 3 4 5
5

</p>